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.
Optionalcode: CodeOptionalmetadata: HeadersInitOptionaloutgoingDetails: Message<AnyMessage>[]Optionalcause: unknownThe 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.
ReadonlycodeThe 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.
ReadonlymetadataA union of response headers and trailers associated with this error.
ReadonlyrawThe 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.
OptionalstackStaticstackThe 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.
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.
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.
Static[hasStaticcaptureCreates 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();
OptionalconstructorOpt: FunctionStaticfromConvert any value - typically a caught error into a ConnectError, following these rules:
Optionalcode: CodeStaticisIndicates whether the argument provided is a built-in Error instance or not.
Staticprepare
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.