https://github.com/flodlc/throw-http
Throw-http is an Error utility for handling http errors in a delightful way. I created it because existing libraries are not type-safe, not correctly exported or don't allow to pass additional data in the error.
https://github.com/flodlc/throw-http
error http node
Last synced: about 1 year ago
JSON representation
Throw-http is an Error utility for handling http errors in a delightful way. I created it because existing libraries are not type-safe, not correctly exported or don't allow to pass additional data in the error.
- Host: GitHub
- URL: https://github.com/flodlc/throw-http
- Owner: flodlc
- License: mit
- Created: 2024-03-03T13:46:11.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-03-04T09:23:34.000Z (about 2 years ago)
- Last Synced: 2025-02-16T23:04:14.586Z (about 1 year ago)
- Topics: error, http, node
- Language: TypeScript
- Homepage:
- Size: 23.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
throw-http
## Introduction
Throw-http is an Error utility for handling http errors in a delightful way.
I created it because existing libraries are not type-safe, not correctly exported or don't allow to pass additional data in the error.
## Installation
To get started, install http-throw using npm or yarn:
```sh
npm install throw-http
# or
yarn add throw-http
```
## Usage
Throwing an ThrowHttp error
```typescript
import { ThrowHttp } from 'throw-http';
throw new ThrowHttp.NotFound('User not found');
```
Throwing a custom ThrowHttp error
```typescript
import { ThrowHttp } from 'throw-http';
throw new ThrowHttp({ code: 500, name: 'Badaboom' });
```
Typeguard for ThrowHttp
```typescript
import { ThrowHttp } from 'throw-http';
try {
// some code
} catch (error) {
if (ThrowHttp.isThrowHttp(error)) {
// handle http error
}
}
```