Skip to content
This repository has been archived by the owner on Feb 7, 2018. It is now read-only.

phenomnomnominal/tractor-error-handler

Repository files navigation

tractor-error-handler

Greenkeeper badge npm version bitHound Overall Score Code Climate Test Coverage

A general HTTP request error handler for tractor.

API:

TractorError:

Creates a new TractorError.

Arguments:

  • message: string - the error message
  • status?: number - the HTTP status of the error

Usage:

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

TractorError.isTractorError:

Checks if something is a TractorError.

Arguments:

  • e: any - thing to test

Usage:

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 object
  • error: TractorError - the TractorError that was thrown

Usage:

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);
   }
}

About

A general HTTP request error handler for tractor

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published