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

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

    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.

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
prepareStackTrace?: ((err, stackTraces) => any)

Type declaration

stackTraceLimit: number

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

    Parameters

    Returns T[]

  • Parameters

    Returns AnyMessage[]

  • Create .stack property on a target object

    Parameters

    • targetObject: object
    • Optional constructorOpt: 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
    • Optional code: Code

    Returns ConnectError

Generated using TypeDoc