https://github.com/dancastillo/error
A small utility for generating consistent errors
https://github.com/dancastillo/error
Last synced: 7 days 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 (8 months ago)
- Default Branch: main
- Last Pushed: 2025-05-12T11:23:32.000Z (10 days ago)
- Last Synced: 2025-05-12T12:34:46.786Z (10 days ago)
- Language: TypeScript
- Size: 35.2 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# @dancastillo/error
A small utility for generating consistent errors
### Install
npm
```bash
npm install @dancastillo/error
```yarn
```bash
npm add @dancastillo/error
```pnpm
```bash
pnpm install @dancastillo/error
```### Usage
```
createError(code, message [, detail [, meta]])
```- `code` (`number`, required) - The error code, you can access it via`error.code`.
- `message` (`string`, required) - The error message.
- `detail` (`string[]`, optional) - The error detail. You can include additional information about the error that has occurred.
- `meta` (`T extends object`, optional) - Additional metadata object that you can pass in with generic.#### TypeScript Example
```ts
import { createError, type DCError } from '@dancastillo/error'type Meta = { userId: string }
const err = createError(500, 'Title', 'Detail', { userId: 'some-user-id' })
console.log(err.code) // 500
console.log(err.title) // 'Title'
console.log(err.detail) // 'Detail'
console.log(err.meta) // { userId: 'some-user-id' }
```#### JavaScript Example
```js
import { createError } from '@dancastillo/error'const err = createError(500, 'Title', 'Detail', { userId: 'some-user-id' })
console.log(err.code) // 500
console.log(err.title) // 'Title'
console.log(err.detail) // 'Detail'
console.log(err.meta) // { userId: 'some-user-id' }
```## License
Licensed under [MIT](./LICENSE).