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

http-error

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

http-error

Expose HTTP error codes as Error objects

  • 0.0.6
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1K
decreased by-6.51%
Maintainers
1
Weekly downloads
 
Created
Source

http-error

Exposes HTTP error codes as Error constructors.

Install

npm install http-error

Example


    var HttpError = require("http-error");

    // in your app:
    app.get("/:project", function(req, res, next){
        db.loadProject(req.params.project, function(err, project){
            if(err) return next(new HttpError.InternalServerError("Something went wrong"));
            if(!project) return next(new HttpError.notFound("This project does not exist"));
            
            res.json(project.toObject());
        });
    });
    
    // in your error handler:
    app.use(function(err, req, res, next){
        res.status(err.code).json({ error: err.message });
    });

List of errors

This module implements the following error constructors:

CodeFunction
400BadRequest
401Unauthorized
402PaymentRequired
403Forbidden
404NotFound
405MethodNotAllowed
406NotAcceptable
407ProxyAuthenticationRequired
408RequestTimeout
409Conflict
410Gone
411LengthRequired
412PreconditionFailed
413RequestEntityTooLarge
414RequestURITooLong
415UnsupportedMediaType
416RequestedRangeNotSatisfiable
417ExpectationFailed
420EnhanceYourCalm
422UnprocessableEntity
423Locked
424FailedDependency
425UnorderedCollection
426UpgradeRequired
428PreconditionRequired
429TooManyRequests
431RequestHeaderFieldsTooLarge
444NoResponse
449RetryWith
450BlockedByWindowsParentalControls
499ClientClosedRequest
500InternalServerError
501NotImplemented
502BadGateway
503ServiceUnavailable
504GatewayTimeout
505HTTPVersionNotSupported
506VariantAlsoNegotiates
507InsufficientStorage
508LoopDetected
509BandwidthLimitExceeded
510NotExtended
511NetworkAuthenticationRequired

FAQs

Package last updated on 19 Jan 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

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