1.0.3 • Published 10 years ago
create-http-error v1.0.3
create-http-error
Simply creates http ERRORs with the given http error code.
install
npm install --save create-http-erroruse
var HttpError = require('create-http-error');
// e.g. as finalhandler after no route matched.
function finalhandler (req, res, next) {
next(HttpError('400'));
}
app.use(finalhandler); // connect or express app.api
HttpError(code ,message)
creates an Error Object:
- with the provided http error
codelike e.g. 500 - if the
messageis omitted, the standardhttperror message is taken. - if a
propertiesObject is provided, it's properties will be added to theErrorObject.
HttpError.toString()
returns the String representation of the HttpError.
HttpError.toJSON()
returns the Javascript Object properties of the HttpError Object.
HttpError.codes
exposes the standard http error codes.
test
npm testlicense
MIT