0.0.6 • Published 8 years ago

http-error v0.0.6

Weekly downloads
956
License
-
Repository
github
Last release
8 years ago

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