0.0.1 • Published 12 years ago
erros v0.0.1
Erros.js
Simple Express error handler
Installation
npm install errosUsage
var app = require('express')();
var erros = require('erros');
// configure your app...
app.use(erros.handler()); // should be last in the middleware stackResponds to content types:
text/htmltext/plainapplication/json
Define your own view folder and view engine extension.
app.use(erros.handle({views: __dirname+'/views', view_ext: 'jade'}));viewsyour views directory, default./view_extview engine extension, defaultjade
Accept: text/html will always attempt to respond with res.render.
Your error pages should be named 5xx.your-extension and 4xx.your-extension for Server and Client errors respectively.
Change the default Status code.
app.use(erros.handle({default_status: 200}));Status code will be 200, unless your error has a status property defining another code. Eg. use of custom Error
function MyError(msg, status) {
Error.captureStackTrace(this);
this.message = msg;
this.name = 'MyError';
this.status = status;
}
MyError.prototype = Object.create(Error.prototype);License
MIT
0.0.1
12 years ago