@synanetics/errors
v2.0.2
Published
Set of Synanetics common errors for applications to use
Downloads
157
Maintainers
Keywords
Readme
@synanetics/errors
Utility Synanetics errors for application usage
SynaneticsOutcomeError
Takes message
and optional options
parameters. Extends default Error
interface with support for cause
and in addition takes optional outcome
and status
properties.
SynaneticsOutcomeError.outcome
The outcome
property is expected to be an OperationOutcome
resource. If not supplied then a default OperationOutcome
with severity
of 'error', code
of 'invalid' and diagnostics matching the message
parameter is created.
SynaneticsOutcomeError.status
The status
property is expected to be a number, it defaults to 500
assuming the value is meant for HTTP status code representation but in theory could be any desired number system.
Usage
const { SynaneticsOutcomeError } = require('@synanetics/errors');
// or
import { SynaneticsOutcomeError } from '@synanetics/errors';
const outcomeError1 = new SynaneticsOutcomeError('some message');
const outcomeError2 = new SynaneticsOutcomeError('example', {
outcome: { resourceType: 'OperationOutcome' ... },
status: 400,
cause: outcomeError1,
});
HttpStatusCodeOutcomeError
Creates Error
objects with extended outcome
and status
properties to represent HTTP related errors. message
parameter can be an array of strings to generate multiple issue entries.
HttpStatusCodeOutcomeError.outcome
The outcome
property will be an OperationOutcome
resource.
HttpStatusCodeOutcomeError.status
The status
property will be a number representing a HTTP status code.
static methods
A number of static methods are available to ease creation of specific types of error that map to the NHS Booking and Referral Standard:
badRequestError() -> BAD_REQUEST
conflictError() -> CONFLICT
forbiddenError() -> FORBIDDEN
methodNotAllowedError() -> METHOD_NOT_ALLOWED
notAcceptableError() -> NOT_ACCEPTABLE
notFoundError() -> NOT_FOUND
notImplementedError() -> NOT_IMPLEMENTED
proxyBadRequestError() -> PROXY_BAD_REQUEST
proxyConflictError() -> PROXY_CONFLICT
proxyForbiddenError() -> PROXY_FORBIDDEN
proxyMethodNotAllowedError() -> PROXY_METHOD_NOT_ALLOWED
proxyNotFoundError() -> PROXY_NOT_FOUND
proxyNotImplementedError() -> PROXY_NOT_IMPLEMENTED
proxyServerError() -> PROXY_SERVER_ERROR
proxyTimeoutError() -> PROXY_TIMEOUT
proxyTooManyRequestsError() -> PROXY_TOO_MANY_REQUESTS
proxyUnauthorizedError() -> PROXY_UNAUTHORIZED
proxyUnavailableError() -> PROXY_UNAVAILABLE
proxyUnprocessableEntityError() -> PROXY_UNPROCESSABLE_ENTITY
recBadRequestError() -> REC_BAD_REQUEST
recConflictError() -> REC_CONFLICT
recForbiddenError() -> REC_FORBIDDEN
recMethodNotAllowedError() -> REC_METHOD_NOT_ALLOWED
recNotAcceptableError() -> REC_NOT_ACCEPTABLE
recNotFoundError() -> REC_NOT_FOUND
recNotImplementedError() -> REC_NOT_IMPLEMENTED
recServerError() -> REC_SERVER_ERROR
recTimeoutError() -> REC_TIMEOUT
recUnauthorizedError() -> REC_UNAUTHORIZED
recUnavailableError() -> REC_UNAVAILABLE
recUnprocessableEntityError() -> REC_UNPROCESSABLE_ENTITY
sendBadRequestError() -> SEND_BAD_REQUEST
sendConflictError() -> SEND_CONFLICT
sendForbiddenError() -> SEND_FORBIDDEN
sendMethodNotAllowedError() -> SEND_METHOD_NOT_ALLOWED
sendNotAcceptableError() -> SEND_NOT_ACCEPTABLE
sendNotImplementedError() -> SEND_NOT_IMPLEMENTED
sendTooManyRequestsError() -> SEND_TOO_MANY_REQUESTS
sendUnauthorizedError() -> SEND_UNAUTHORIZED
sendUnprocessableEntityError() -> SEND_UNPROCESSABLE_ENTITY
serverError() -> SERVER_ERROR
timeoutError() -> TIMEOUT
tooManyRequestsError() -> TOO_MANY_REQUESTS
unauthorizedError() -> UNAUTHORIZED
unavailableError() -> UNAVAILABLE
unprocessableEntityError() -> UNPROCESSABLE_ENTITY
Additional static methods exist to create outcome errors from HTTP status codes:
HttpStatusCodeOutcomeError.errorFromStatusCode(code, message);
HttpStatusCodeOutcomeError.proxyErrorFromStatusCode(code, message);
HttpStatusCodeOutcomeError.recErrorFromStatusCode(code, message);
HttpStatusCodeOutcomeError.sendEerrorFromStatusCode(code, message);