https://github.com/unlight/errorlings
Custom errors
https://github.com/unlight/errorlings
custom-errors
Last synced: 7 months ago
JSON representation
Custom errors
- Host: GitHub
- URL: https://github.com/unlight/errorlings
- Owner: unlight
- License: mit
- Created: 2019-01-08T19:46:44.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2019-02-02T21:18:01.000Z (over 7 years ago)
- Last Synced: 2025-01-01T01:35:01.545Z (over 1 year ago)
- Topics: custom-errors
- Language: TypeScript
- Size: 333 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# errorlings
Common errors for your application.
## API
Create error (all parameters optional and can be passed in any order)
```ts
const e = new CustomEror(status: number, message: string, code: string, inner: Error, { data: any });
```
Rules of detecting type of parameter:
* typeof number: status
* first string: message
* second string: code
* instanceof Error: inner
* object with key data: data
Using options object as parameter:
```ts
const err = new CustomEror({
status?: number;
data?: any;
code?: string;
inner?: Error;
message?: string;
});
```
### Error classes and defaults
* `ExceptionError`
* `ForbiddenError` (status: 403, message: You don't have permission to do that.)
* `NotFoundError` (status: 404)
* `ValidationError` (status: 400)
## Changelog
See [CHANGELOG.md](CHANGELOG.md)
## Similar Projects
* https://github.com/shutterstock/node-common-errors