function isTrap
isTrap(reply: Reply): reply is TrapReply

Checks if a reply is a trap (error) reply

Type guard function that narrows the Reply type to TrapReply.

Examples

Handle trap errors

import { assertEquals } from "@std/assert";
import { parseReply, isTrap } from "@hertzg/routeros-api/protocol/reply";

const reply = parseReply(["!trap", "=message=no such item"]);
if (isTrap(reply)) {
  // TypeScript knows reply has message property here
  assertEquals(reply.message, "no such item");
}

Parameters

reply: Reply

The reply to check

Return Type

reply is TrapReply

True if the reply is a TrapReply

Usage

import { isTrap } from "protocol/reply.ts";