https://github.com/remscodes/thror
🏮 Simple error creation utility
https://github.com/remscodes/thror
error exception javascript typescript
Last synced: 4 months ago
JSON representation
🏮 Simple error creation utility
- Host: GitHub
- URL: https://github.com/remscodes/thror
- Owner: remscodes
- License: mit
- Created: 2023-08-07T15:23:50.000Z (almost 3 years ago)
- Default Branch: main
- Last Pushed: 2024-10-27T19:58:09.000Z (over 1 year ago)
- Last Synced: 2025-06-14T03:19:50.764Z (about 1 year ago)
- Topics: error, exception, javascript, typescript
- Language: TypeScript
- Homepage: https://npm.im/thror
- Size: 482 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
Thror
Simple error creation utility
[](https://github.com/remscodes/thror/actions/workflows/npm-ci.yml)
[](https://codecov.io/gh/remscodes/thror)
[](https://www.npmjs.org/package/thror)
[](https://bundlephobia.com/package/thror)
[](LICENSE)
## Installation
```shell
npm install thror
```
## Usage
### Create Error
##### createError(name, message, extra?)
Example :
```ts
import { createError } from 'thror';
const err = createError('MyException', 'Cannot create user without username.', { status: 400 });
console.log(err.name); // MyException
console.log(err.message); // Cannot create user without username.
console.log(err.status); // 400
console.log(err instanceof Error) // true
throw err; // [MyException: Cannot create user without username.] { status: 400 }
```
### Emit Error
##### emitError(name, message, extra?)
Example :
```ts
import { emitError } from 'thror';
// will immediately throw the created error
emitError('MyException', 'Cannot create user without username.', { status: 400 }) // [MyException: Cannot create user without username.] { status: 400 }
```
### Extra
```ts
interface ErrorExtra {
// Preserves the error stack.
// default : false
withStack?: boolean;
// The original error.
// For example in the case you want to display a clearer error with Thror and store the original one.
original?: any;
// Whatever you want.
[key: string]: any;
}
```
## License
[MIT](LICENSE) © Rémy Abitbol.