1.0.0 • Published 9 months ago

@adobe/contentlake-shared-rest-error v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
9 months ago

Content Lake Shared - REST Error

Error type for returning rfc9457 problem responses

This is one of the Content Lake Shared libraries.

Status

GitHub license

Usage

Install using:

npm install @adobe/contentlake-shared-rest-error

Use with:

import { RestError } from '@adobe/contentlake-shared-rest-error';

throw new RestError(400, 'Missing some field');

Additional Properties

To add additional requests to the error body provide a third parameter as an Object:

throw new RestError(400, 'Missing some field', { fields: ['field1', 'field2']});

Converting to a Problem Response

The static method toProblemResponse can convert any object (including RestError objects) into a rfc9457 problem responses:

RestError.toProblemResponse(err);

In addition, you can provide a second context parameter from which the method will extract an instance from the invocation:

RestError.toProblemResponse(err, context);