Skip to main content

MiddlewareFactory.error()

Home > @backstage/backend-app-api > MiddlewareFactory > error

Express middleware to handle errors during request processing.

Signature:

error(options?: MiddlewareFactoryErrorOptions): ErrorRequestHandler;

Parameters

ParameterTypeDescription
optionsMiddlewareFactoryErrorOptions(Optional)

Returns:

ErrorRequestHandler

An Express error request handler

Remarks

This is commonly the very last middleware in the chain.

Its primary purpose is not to do translation of business logic exceptions, but rather to be a global catch-all for uncaught "fatal" errors that are expected to result in a 500 error. However, it also does handle some common error types (such as http-error exceptions, and the well-known error types in the @backstage/errors package) and returns the enclosed status code accordingly.

It will also produce a response body with a serialized form of the error, unless a previous handler already did send a body. See ErrorResponseBody for the response shape used.