Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/calebmer/shenanigans
A sane way to do errors in a node app
https://github.com/calebmer/shenanigans
Last synced: 11 days ago
JSON representation
A sane way to do errors in a node app
- Host: GitHub
- URL: https://github.com/calebmer/shenanigans
- Owner: calebmer
- License: mit
- Created: 2015-10-23T19:41:42.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-01-24T21:19:04.000Z (almost 8 years ago)
- Last Synced: 2024-12-03T11:41:06.732Z (22 days ago)
- Language: JavaScript
- Size: 3.91 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shenanigans
A sane way to do errors in a node app.
How you ask?
Well requiring custom errors isn’t too fun so this module takes your error message of shenanigans syntax, parses it, and returns an object with some much friendlier properties.
```js
const Shenanigans = require('./shenanigans')try {
throw new Error('403: Not allowed to access resource (Try logging in)')
}
catch (error) {
const info = Shenanigans.parse(error)
console.log(info) // => { statusCode: 403, message: 'Not allowed to access resource', hint: 'Try logging in' }
}
```And for some real fun if you are using HTTP status codes
```js
const Shenanigans = require('./shenanigans')try {
throw new Error(404)
}
catch (error) {
const info = Shenanigans.parse(error)
console.log(info) // => { statusCode: 404, message: 'Not Found' }
}
```## Syntax
```
${status code}: ${message} (${hint})
```Where status code is a number.
## API
### Shenanigans.parse(message[, options])
Parses the message and returns an info object.
Options are booleans which enable/disable features, they are all true by default and they include:
- `statusCode`: Parse the HTTP status code
- `hint`: Parse the hint
- `assertion`: Enable the assertion error special case