Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dancastillo/error
A small utility for generating consistent errors
https://github.com/dancastillo/error
Last synced: about 1 month ago
JSON representation
A small utility for generating consistent errors
- Host: GitHub
- URL: https://github.com/dancastillo/error
- Owner: dancastillo
- License: mit
- Created: 2024-09-13T00:50:35.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-11-11T10:15:51.000Z (about 1 month ago)
- Last Synced: 2024-11-11T11:25:43.035Z (about 1 month ago)
- Language: TypeScript
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# @dancastillo/error
A small utility for generating consistent errors
### Install
```bash
npm install @dancastillo/error
```### Usage
```
createError(code, message [, details [, statusCode [, error]]])
```- `code` (`string`, required) - The error code, you can access it via`error.code`. For consistency, it is recommended using [ErrorCode](./src/types/index.ts)
- `message` (`string`, required) - The error message. This can be customized to use interpolated strings for formatting the message.
- `details` (`string[]`, optional) - The error details. You can include additional information about the error that has occurred. Default is an empty array.
- `statusCode` (`number`, optional) - The status code that will be used if you want to sent via HTTP. Note this will be automatically populated based on the `code` you pass in```js
import createError from '@dancastillo/errorconst CreatedError = createError('INTERNAL_ERROR', 'Error happened')
const err = CreatedError()
console.log(err.code) // 'INTERNAL_ERROR'
console.log(err.message) // 'Error happened'
```## License
Licensed under [MIT](./LICENSE).