https://github.com/supercharge/http-errors
Beautiful HTTP error classes
https://github.com/supercharge/http-errors
Last synced: 11 months ago
JSON representation
Beautiful HTTP error classes
- Host: GitHub
- URL: https://github.com/supercharge/http-errors
- Owner: supercharge
- License: mit
- Created: 2021-08-20T11:34:47.000Z (almost 5 years ago)
- Default Branch: main
- Last Pushed: 2024-03-10T05:06:23.000Z (about 2 years ago)
- Last Synced: 2025-07-06T20:07:59.771Z (11 months ago)
- Language: TypeScript
- Size: 25.4 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
HTTP Errors
An HTTP error class throwing with proper status codes
Follow @marcuspoehls and @superchargejs for updates!
---
## Introduction
The `@supercharge/http-errors` package provides an HTTP error class with useful defaults.
- provides an `HttpError` base class with defaults to throw proper HTTP errors
- the `HttpError` base class captures stack traces by default
- create your own HTTP error with custom HTTP status code, title, and error code
## Installation
```
npm i @supercharge/http-errors
```
## Quick Usage Overview
Using `@supercharge/http-errors` is pretty straightforward. The package exports the `HttpError` class that you can use like the native `Error` class.
```js
const { HttpError } = require('@supercharge/http-errors')
// create an HTTP 400 BadRequest error yourself
throw new HttpError('invalid request input data', 400)
// … or throw using shortcut methods
throw HttpError.badRequest('Request validation failed')
// … or use a fluent interface to customize the properties
throw new HttpError('Request validation failed')
.withStatus(400)
.withCode('E_YOUR_CUSTOM_ERROR_CODE')
```
## Contributing
Do you miss a function? We very much appreciate your contribution! Please send in a pull request 😊
1. Create a fork
2. Create your feature branch: `git checkout -b my-feature`
3. Commit your changes: `git commit -am 'Add some feature'`
4. Push to the branch: `git push origin my-new-feature`
5. Submit a pull request 🚀
## License
MIT © [Supercharge](https://superchargejs.com)
---
> [superchargejs.com](https://superchargejs.com) ·
> GitHub [@supercharge](https://github.com/supercharge) ·
> Twitter [@superchargejs](https://twitter.com/superchargejs)