# throwable-http-errors

> Throwable HTTP Errors for node apis

Latest version **2.0.3** (published 2025-01-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install throwable-http-errors
pnpm add throwable-http-errors
yarn add throwable-http-errors
bun add throwable-http-errors
```

## Health

**Score 35/100 (D)** — status: maintenance-mode.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: stale; low maintenance score.

## Facts

| | |
|---|---|
| Version | 2.0.3 |
| Published | 2025-01-21 |
| First published | 2018-03-02 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 45.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 3 |
| Author | Mattia Alfieri |
| Maintainers | fatmatto |
| Keywords | es6, error, http |

## Links

- npm: https://www.npmjs.com/package/throwable-http-errors
- Repository: https://github.com/fatmatto/throwable-http-errors
- Homepage: https://github.com/fatmatto/throwable-http-errors#readme
- Issues: https://github.com/fatmatto/throwable-http-errors/issues
- npm.io page: https://npm.io/package/throwable-http-errors

## Alternatives

- [@sentry/react-native](https://npm.io/package/@sentry/react-native.md) — 2.6M weekly downloads
- [@ardatan/aggregate-error](https://npm.io/package/@ardatan/aggregate-error.md) — 708.1K weekly downloads
- [custom-error-generator](https://npm.io/package/custom-error-generator.md) — 2.0K weekly downloads
- [@technik-sde/prosemirror-recreate-transform](https://npm.io/package/@technik-sde/prosemirror-recreate-transform.md) — 1.5K weekly downloads
- [@suchipi/error-utils](https://npm.io/package/@suchipi/error-utils.md) — 78 weekly downloads

## Recent versions

- 2.0.3 (latest) — 2025-01-21
- 2.0.2 — 2022-08-03
- 2.1.0 — 2020-10-13
- 2.0.1 — 2020-10-12
- 2.0.0 — 2020-03-16
- 1.0.1 — 2018-03-25
- 1.0.0 — 2018-03-02

## README

[![Build Status](https://travis-ci.org/fatmatto/throwable-http-errors.svg?branch=master)](https://travis-ci.org/fatmatto/throwable-http-errors)

# Throwable HTTP errors

Throwable HTTP errors for node APIs.

## Installation

```bash
npm i throwable-http-errors
```

## Usage

```javascript
const Errors = require('throwable-http-errors')

// for example, using express.js
router.post('/', wrap(async (req, res, next) => {
  try {
    if (!validatePet(req.body)) {
      throw new Errors.BadRequest()
    }

    const pet = await PetsController.create(req.body)
    res.send({ status: true, data: pet })
  } catch (e) {
    return next(e)
  }
}))
```

## Reason

Before async/await, I was used to send errors to the main error catching middleware just by running

```javascript
return next(new Errors.BadRequest())
```

Now, with async/await we can leverage try/catch blocks to handle errors. While I'm not quite happy with having try/catch blocks in every route, having **await** for promises improves code readablity (and quality in my opinion) a lot.

---
_Source: https://npm.io/package/throwable-http-errors · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
