Errors
Domain exceptions used by createWorker to translate failures into structured HTTP responses. All three classes extend Error, accept a constructor argument, and produce a useful message automatically.
Importing
import {
InvalidValueError,
MissingParameterError,
NotFoundError
} from '@basmilius/worker';HTTP status mapping
createWorker recognises every class on this page. The error response uses the exception's message as error_description.
| Class | HTTP status | Error code |
|---|---|---|
MissingParameterError | 400 | missing_parameter |
NotFoundError | 404 | not_found |
InvalidValueError | 406 | invalid_value |
| (any other thrown value) | 500 | internal_server_error |
MissingParameterError
Signal that a required query parameter (or other input) is absent. The constructor takes the parameter name and produces the message "Missing required parameter <name>.".
import { MissingParameterError } from '@basmilius/worker';
throw new MissingParameterError('date');
// -> "Missing required parameter date."Thrown automatically by queryDate, queryInteger and queryPosition.
Type signature
declare class MissingParameterError extends Error {
constructor(param: string);
}InvalidValueError
Signal that an input was present but malformed. The constructor takes the parameter name and produces the message "Invalid value for parameter <name>.".
import { InvalidValueError } from '@basmilius/worker';
throw new InvalidValueError('latitude');
// -> "Invalid value for parameter latitude."Thrown automatically by queryDate, queryInteger and queryPosition.
Type signature
declare class InvalidValueError extends Error {
constructor(param: string);
}NotFoundError
Signal that a requested resource does not exist. Unlike the other two errors, this one takes a free-form message that becomes the user-visible error_description.
import { NotFoundError } from '@basmilius/worker';
throw new NotFoundError('Order not found.');Type signature
declare class NotFoundError extends Error {
constructor(message: string);
}