Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/purwokertodev/http-restify-error
a custom http error for restify package
https://github.com/purwokertodev/http-restify-error
restify restify-server
Last synced: about 2 months ago
JSON representation
a custom http error for restify package
- Host: GitHub
- URL: https://github.com/purwokertodev/http-restify-error
- Owner: purwokertodev
- Created: 2017-03-07T07:11:24.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-03-07T11:02:31.000Z (almost 8 years ago)
- Last Synced: 2024-11-02T21:51:33.415Z (2 months ago)
- Topics: restify, restify-server
- Language: JavaScript
- Size: 7.81 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
- SIMPLE HTTP ERROR CUSTOM FOR RESTIFY
When you dealing with callback, sometime you confuse which error you need to handle.
Because you don't know where the error comes from.USAGE:
-repository.js
```javascript
'use strict'
const httpError = require('http-restify-error');
function find(id, cb){
cb({error: httpError.ERROR_TYPE.NOT_FOUND, msg: `user with id ${id} not found`}, null);
}module.exports = find;
```
-handler.js
```javascript
'use strict';
const httpError = require('http-restify-error');
const find = require('./repository');
function getExample(req, res, next){
let id = 1;
find(id, (err, data) => {
res.send(httpError.error(err.error, err.msg));
});
}module.exports = {
getExample: getExample
};```
-index.js
```javascript
'use strict';
const restify = require('restify');
const handler = require('./handler');
const server = restify.createServer({
versions: "0.0.1",
name: 'MyApp',
});server.get('/', (req, res, next) => {
res.send("Test........");
});server.get('/error-test', handler.getExample);
server.listen(3000);
```
This package build from https://github.com/restify/errors