Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

httpexceptions

Package Overview
Dependencies
Maintainers
1
Versions
19
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

httpexceptions

Provide exception for HTTP Rest API

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

HTTPExceptions Build Status

Provide Exceptions for REST API based on Express.js.

This module lets you to throw an HTTPException quickly.

Features

  • Very Simple API
  • Two middlewares are available. HTTPException.mime() and HTTPException.globalHandler()

Some HTTP Exception are already implemented :

  • BadRequest
  • Unauthorized
  • PaymentRequired
  • Forbidden
  • NotFound
  • MethodNotAllowed
  • NotAcceptable
  • InternalServerError
  • NotImplemented
  • BadGateway
  • ProxyError
  • ServiceUnvailable
  • GatewayTimeout

You can use HTTPException method to throw a custom Exception (see example).

Install

Use npm install httpexceptions.

API

   var httpException = require('httpexception');
   var express = require('express');
   var app = express();
   
   httpException.debug(true);
   
   app.use(httpException.mime('application/json'));
   app.use(httpException.paramsRequired());
   
   // OR
   // app.use(httpException.mime(['application/json', 'text/xml']));
   
   app.get('/my/route/exception', function(req, res){
   
        throw new httpException.BadRequest('Custom Message'); //Emit 
        
        // OR
        // throw new httpException.HTTPException(510, 'Custom Message');
   
   });
   
   app.get('/my/route/params', function(req, res){
      
        req.paramsRequired({
            query:['id']
        }); //throw a BadRequest exception if the parameters id isn't defined in queryParams
  
   });
   
   //at the end
   //GlobalHandler middleware catch exception and send response to the client
   app.use(httpException.globalHandler());

Use Typescript definition

This module is written in Typescript. But don't use import HttpExceptions = require('httpexceptions') instead of var httpException = require('httpexception');. It's little buggy because, Error type in typescript is declared as variable / interface and when you import module, the compilator fail.

So, you can find file definition httpexceptions.d.ts in the module.

   /// <reference path="node_modules/httpexceptions/httpexceptions.d.ts" />
   
   var httpException = require('httpexception');

Test

Use npm test.

Keywords

FAQs

Package last updated on 09 Dec 2015

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc