A general HTTP request error handler for tractor.
Creates a new
TractorError
.
message: string
- the error messagestatus?: number
- the HTTP status of the error
let error = new TractorError('something bad happened', 500);
Checks if something is a
TractorError
.
e: any
- thing to test
TractorError.isTractorError(new TractorError('something bad happened')); // true; TractorError.isTractorError(new Error('something bad happened')); // false;
Sends an error back to the client
response:
Response - the Express HTTP response objecterror: TractorError
- the TractorError that was thrown
import { TractorError, handleError } from 'tractor-error-handler'; export function myApiEndpoint (request, response) { if (somethingBad) { handleError(response, new TractorError('something bad happened')); } else { response.sendStatus(200); } }