@tractor/error-handler
TypeScript icon, indicating that this package has built-in type declarations

1.9.4-tractor-to-playwright.0 • Public • Published

@tractor/error-handler

A general HTTP request error handler for tractor.

npm version

API

new TractorError (message: string, status?: number)

Create a new TractorError.

const error = new TractorError('something bad happened', 500);

TractorError.isTractorError (err: TractorError | any): boolean

Checks if something is a TractorError.

TractorError.isTractorError(new TractorError('something bad happened')); // true;
TractorError.isTractorError(new Error('something bad happened')); // false;

handleError (response: Response, err: TractorError, message?: string): void

Sends an error back to the client, via the Express HTTP response object.

import { TractorError, handleError } from '@tractor/error-handler';

export function myApiEndpoint (request: Request, response: Response): void {
    if (somethingBad) {
        handleError(response, new TractorError('something bad happened'));
    } else {
        response.sendStatus(200);
    }
}

Readme

Keywords

none

Package Sidebar

Install

npm i @tractor/error-handler

Weekly Downloads

48

Version

1.9.4-tractor-to-playwright.0

License

MIT

Unpacked Size

9.26 kB

Total Files

19

Last publish

Collaborators

  • phenomnomnominal
  • trbpro23
  • amy.rowell
  • mzollner
  • deemicksee
  • cgrant_tm
  • savage-tm