0.2.4 • Published 7 years ago
tractor-error-handler v0.2.4
tractor-error-handler
A general HTTP request error handler for tractor.
API:
TractorError
:
Creates a new
TractorError
.Arguments:
message: string
- the error messagestatus?: number
- the HTTP status of the errorUsage:
let error = new TractorError('something bad happened', 500);
TractorError.isTractorError
:
Checks if something is a
TractorError
.Arguments:
e: any
- thing to testUsage:
TractorError.isTractorError(new TractorError('something bad happened')); // true; TractorError.isTractorError(new Error('something bad happened')); // false;
handleError
:
Sends an error back to the client
Arguments:
response:
Response - the Express HTTP response objecterror: TractorError
- the TractorError that was thrownUsage:
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); } }
0.2.4
7 years ago
0.2.3
7 years ago
0.2.2
7 years ago
0.2.1
7 years ago
0.2.0
7 years ago
0.2.0-beta.1
7 years ago
0.2.0-beta.0
7 years ago
0.1.4
7 years ago
0.1.3
7 years ago
0.1.2
7 years ago
0.1.1
7 years ago
0.1.0
8 years ago
0.1.0-beta.0
8 years ago