Skip to content

Fblind/http-error

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

HTTP Error

JavaScript Style Guide CircleCI

This module expose an error to be thrown for http projects

Install

$ npm install http-error

Error properties

  • code: Represents an internal error code, defaults into an empty string
  • message: Represents a human-readable message explaining the situation, defaults into an empty string
  • statusCode: Represent a HTTP status code, defaults to 400

Usage

const HttpError = require('http-error')

throw new HttpError()
// you will get: code = '', message = '', status = 400

throw new HttpError('PRODUCT_NOT_EXISTS')
// you will get: code = 'PRODUCT_NOT_EXISTS', message = '', status = 400

throw new HttpError('PRODUCT_NOT_EXISTS', 'The product you are trying to see does not exists')
// you will get: code = 'PRODUCT_NOT_EXISTS', message = 'The product you are trying to see does not exists', status = 400

throw new HttpError('PRODUCT_NOT_EXISTS', 'The product you are trying to see does not exists', 404)
// you will get: code = 'PRODUCT_NOT_EXISTS', message = 'The product you are trying to see does not exists', status = 404