New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

hata

Package Overview
Dependencies
Maintainers
2
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hata

Common HTTP errors to be used with express.js or whatever engine you use.

latest
Source
npmnpm
Version
0.4.0
Version published
Maintainers
2
Created
Source

Hata (HTTP Errors)

Travis CI npm npm Codecov VersionEye

Common HTTP errors to be used with express.js or whatever engine you use.

The name

Hata means "error" in Arabic (and Turkish!), which is where the package name comes from.

Features

The following error types are currently supported:

  • (400) bad-request: BadRequestError
  • (401) unauthorized: UnauthorizedError
  • (403) forbidden: ForbiddenError
  • (404) not-found: NotFoundError
  • (409) conflict: ConflictError
  • (422) unprocessable-entity: UnprocessableEntityError

The error object is an instance of Error, with the properties name, message and stack.

Usage

var NotFoundError = require('hata/not-found');

throw new NotFoundError('Product not found');

You can also add more properties to the error object by passing them as the second parameter.

var NotFoundError = require('hata/not-found');

var error = new NotFoundError('Product not found', { item: 'product', id: 1, });
// error now has attributes `item` and `id`.

You can also use it in the following way:

var hata = require('hata');
var error = hata(404/*, message, obj*/);

Express

Just add a regular error handler like the following:

// http://expressjs.com/guide/error-handling.html
app.use(function(err, req, res, next) { // jshint ignore:line
  return res
            .status(err.httpCode || 500)
            .header('content-type: application/json')
            .send(safeJsonStringify(err));
});

Keywords

http

FAQs

Package last updated on 06 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts