Viam SDK
    Preparing search index...

    Class ConnectError

    ConnectError captures four pieces of information: a Code, an error message, an optional cause of the error, and an optional collection of arbitrary Protobuf messages called "details".

    Because developer tools typically show just the error message, we prefix it with the status code, so that the most important information is always visible immediately.

    Error details are wrapped with google.protobuf.Any on the wire, so that a server or middleware can attach arbitrary data to an error. Use the method findDetails() to retrieve the details.

    Hierarchy

    • Error
      • ConnectError
    Index

    Constructors

    • Create a new ConnectError. If no code is provided, code "unknown" is used. Outgoing details are only relevant for the server side - a service may raise an error with details, and it is up to the protocol implementation to encode and send the details along with error.

      Parameters

      • message: string
      • Optionalcode: Code
      • Optionalmetadata: HeadersInit
      • OptionaloutgoingDetails: Message<AnyMessage>[]
      • Optionalcause: unknown

      Returns ConnectError

    Properties

    cause: unknown

    The underlying cause of this error, if any. In cases where the actual cause is elided with the error message, the cause is specified here so that we don't leak the underlying error, but instead make it available for logging.

    code: Code

    The Code for this error.

    details: (Message<AnyMessage> | IncomingDetail)[]

    When an error is parsed from the wire, incoming error details are stored in this property. They can be retrieved using findDetails().

    When an error is constructed to be sent over the wire, outgoing error details are stored in this property as well.

    message: string
    metadata: Headers

    A union of response headers and trailers associated with this error.

    name: string
    rawMessage: string

    The error message, but without a status code in front.

    For example, a new ConnectError("hello", Code.NotFound) will have the message [not found] hello, and the rawMessage hello.

    stack?: string
    stackTraceLimit: number

    The Error.stackTraceLimit property specifies the number of stack frames collected by a stack trace (whether generated by new Error().stack or Error.captureStackTrace(obj)).

    The default value is 10 but may be set to any valid JavaScript number. Changes will affect any stack trace captured after the value has been changed.

    If set to a non-number value, or set to a negative number, stack traces will not capture any frames.

    Methods

    • Retrieve error details from a ConnectError. On the wire, error details are wrapped with google.protobuf.Any, so that a server or middleware can attach arbitrary data to an error. This function decodes the array of error details from the ConnectError object, and returns an array with the decoded messages. Any decoding errors are ignored, and the detail will simply be omitted from the list.

      Type Parameters

      • T extends Message<T>

      Parameters

      • type: MessageType<T>

      Returns T[]

    • Retrieve error details from a ConnectError. On the wire, error details are wrapped with google.protobuf.Any, so that a server or middleware can attach arbitrary data to an error. This function decodes the array of error details from the ConnectError object, and returns an array with the decoded messages. Any decoding errors are ignored, and the detail will simply be omitted from the list.

      Parameters

      • registry: IMessageTypeRegistry

      Returns AnyMessage[]

    • Parameters

      • v: unknown

      Returns boolean

    • Creates a .stack property on targetObject, which when accessed returns a string representing the location in the code at which Error.captureStackTrace() was called.

      const myObject = {};
      Error.captureStackTrace(myObject);
      myObject.stack; // Similar to `new Error().stack`

      The first line of the trace will be prefixed with ${myObject.name}: ${myObject.message}.

      The optional constructorOpt argument accepts a function. If given, all frames above constructorOpt, including constructorOpt, will be omitted from the generated stack trace.

      The constructorOpt argument is useful for hiding implementation details of error generation from the user. For instance:

      function a() {
      b();
      }

      function b() {
      c();
      }

      function c() {
      // Create an error without stack trace to avoid calculating the stack trace twice.
      const { stackTraceLimit } = Error;
      Error.stackTraceLimit = 0;
      const error = new Error();
      Error.stackTraceLimit = stackTraceLimit;

      // Capture the stack trace above function b
      Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
      throw error;
      }

      a();

      Parameters

      • targetObject: object
      • OptionalconstructorOpt: Function

      Returns void

    • Convert any value - typically a caught error into a ConnectError, following these rules:

      • If the value is already a ConnectError, return it as is.
      • If the value is an AbortError from the fetch API, return the message of the AbortError with code Canceled.
      • For other Errors, return the error message with code Unknown by default.
      • For other values, return the values String representation as a message, with the code Unknown by default. The original value will be used for the "cause" property for the new ConnectError.

      Parameters

      • reason: unknown
      • Optionalcode: Code

      Returns ConnectError

    • Indicates whether the argument provided is a built-in Error instance or not.

      Parameters

      • error: unknown

      Returns error is Error