Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/vedi/http-statuses
Http error wrapper
https://github.com/vedi/http-statuses
Last synced: about 1 month ago
JSON representation
Http error wrapper
- Host: GitHub
- URL: https://github.com/vedi/http-statuses
- Owner: vedi
- License: mit
- Created: 2014-07-07T03:08:27.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-02-16T05:40:29.000Z (almost 8 years ago)
- Last Synced: 2024-09-17T05:19:10.858Z (3 months ago)
- Language: JavaScript
- Size: 5.86 KB
- Stars: 2
- Watchers: 3
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
HTTP statuses for Node
==========
Module to work with http statuses in Node.Usage
-----Require this module in your code and get a status object by key.
Status objects contain `code`, `message` and `createError` method to create convinient node.js
`Error` instance with all status data included.Example
-----```
var express = require('express');
var Q = require('q');
var HTTP_STATUSES = require('http-statuses');
var app = express();app.get('/', function (req, res) {
Q
.try(function () {
if (!req.param('ok')) {
throw HTTP_STATUSES.BAD_REQUEST.createError("Not ok");
}
res.send("ok", HTTP_STATUSES.OK.code);
})
.catch(function(err) {
res.send(err.message, err.httpStatus.code);
});
});var server = app.listen(3000, function() {
console.log('Listening on port %d', server.address().port);
});```