Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Simple error handler middleware for express
tree: 500c30788c

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
http
index.js
package.json
readme.md

readme.md

Express errors

Available in NPM npm install express-errors

Provides easy access to common http errors for express e.g.

  • 400 - Bad request
  • 401 - Unathorized
  • 403 - Forbidden
  • 404 - NotFound
  • 500 - Internal server error

Example

You need create views/errors directory and add 401,403,404 error views.

    var errors = require('express-errors');

    errors.bind(app, { layout: false });

    app.get('/400', function(req, res, next){
      next(errors.BadRequest); // You will get "bad request" error
    });

    app.get('/500', function(req, res, next){
      next(new Error('Something went wrong :(')); // You will get "Internal server error" error
    })

Defining an error

Yeah, you can. Use .define method:

    errors.define({
      name: 'BadRequest', // You will be able to access it through `errors.BadRequest` in future
      message: 'Bad request', // This message for XHR requests
      status: 400 // HTTP status
    });

TODO

  • Bundled views
  • More options
Something went wrong with that request. Please try again.