Skip to main content

@backstage/errors

Home > @backstage/errors

Common utilities for error handling within Backstage

Classes

Class

Description

AuthenticationError

The request requires authentication, which was not properly supplied.

ConflictError

The request could not complete due to a conflict in the current state of the resource.

CustomErrorBase

A base class that custom Error classes can inherit from.

ForwardedError

An error that forwards an underlying cause with additional context in the message.

The name property of the error will be inherited from the cause if possible, and will otherwise be set to 'Error'.

InputError

The given inputs are malformed and cannot be processed.

NotAllowedError

The authenticated caller is not allowed to perform this request.

NotFoundError

The requested resource could not be found.

Note that this error usually is used to indicate that an entity with a given ID does not exist, rather than signalling that an entire route is missing.

NotImplementedError

The server does not support the functionality required to fulfill the request.

NotModifiedError

The requested resource has not changed since last request.

ResponseError

An error thrown as the result of a failed server request.

The server is expected to respond on the ErrorResponseBody format.

ServiceUnavailableError

The server is not ready to handle the request.

Functions

Function

Description

assertError(value)

Asserts that an unknown value is an ErrorLike object, which guarantees that it's an object that has at least two string properties: a non-empty name and message.

If the value is not an ErrorLike object, an error is thrown.

deserializeError(data)

Deserializes a serialized error object back to an Error.

isError(value)

Checks whether an unknown value is an ErrorLike object, which guarantees that it's an object that has at least two string properties: a non-empty name and message.

parseErrorResponseBody(response)

Attempts to construct an ErrorResponseBody out of a failed server request. Assumes that the response has already been checked to be not ok. This function consumes the body of the response, and assumes that it hasn't been consumed before.

The code is forgiving, and constructs a useful synthetic body as best it can if the response body wasn't on the expected form.

serializeError(error, options)

Serializes an error object to a JSON friendly form.

stringifyError(error)

Stringifies an error, including its name and message where available.

Type Aliases

Type Alias

Description

ConsumedResponse

ConsumedResponse represents a Response that is known to have been consumed. The methods and properties used to read the body contents are therefore omitted.

ErrorLike

An object that is shaped like an Error.

ErrorResponseBody

A standard shape of JSON data returned as the body of backend errors.

SerializedError

The serialized form of an Error.