# @rowanmanning/get-error-http-status

> Get the HTTP status code for an error object

Latest version **5.1.0** (published 2026-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install @rowanmanning/get-error-http-status
pnpm add @rowanmanning/get-error-http-status
yarn add @rowanmanning/get-error-http-status
bun add @rowanmanning/get-error-http-status
```

## Health

**Score 75/100 (B)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance; recently updated; high maintenance score; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 5.1.0 |
| Published | 2026-09-11 |
| First published | 2022-11-14 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | 22.x \|\| 24.x \|\| 26.x |
| Dependencies | 0 |
| Unpacked size | 7.5 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| GitHub stars | 0 |
| Author | Rowan Manning |
| Maintainers | rowanmanning |
| Keywords | error, http, status |

## Links

- npm: https://www.npmjs.com/package/@rowanmanning/get-error-http-status
- Repository: https://github.com/rowanmanning/get-error-http-status
- Issues: https://github.com/rowanmanning/get-error-http-status/issues
- npm.io page: https://npm.io/package/@rowanmanning/get-error-http-status

## 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

- 5.1.0 (latest) — 2026-09-11
- 5.0.0 — 2026-09-09
- 4.2.0 — 2025-05-21
- 4.1.2 — 2025-03-16
- 4.1.1 — 2025-03-08
- 4.1.0 — 2025-03-02
- 4.0.0 — 2025-03-02
- 3.2.2 — 2024-07-24
- 3.2.1 — 2024-07-06
- 3.2.0 — 2024-06-23
- 3.1.0 — 2024-01-30
- 3.0.1 — 2024-01-15
- 3.0.0 — 2023-09-11
- 2.0.1 — 2023-04-18
- 2.0.0 — 2023-03-25
- … 3 more at https://npm.io/package/@rowanmanning/get-error-http-status/versions

## README

# @rowanmanning/get-error-http-status

Get the HTTP status code for an error object.

* [Requirements](#requirements)
* [Usage](#usage)
  * [`getErrorHttpStatus`](#geterrorhttpstatus)
  * [`isErrorHttpStatus`](#iserrorhttpstatus)
* [Migration](#migration)
* [Contributing](#contributing)
* [License](#license)


## Requirements

This library requires the following to run:

  * [Node.js](https://nodejs.org/) 22+


## Usage

Install with [npm](https://www.npmjs.com/):

```sh
npm install @rowanmanning/get-error-http-status
```

Import the library into your code:

```js
import { getErrorHttpStatus } from '@rowanmanning/get-error-http-status';
```

### `getErrorHttpStatus`

Call the method with an error object to get the status code:

```js
const notFoundError = new Error('Not Found');
notFoundError.status = 404;

const status = getErrorHttpStatus(error); // 404
```

If there is no `status` property present on the error, then we fall back to the `statusCode` property:

```js
const notFoundError = new Error('Not Found');
notFoundError.statusCode = 404;

const status = getErrorHttpStatus(error); // 404
```

If the `status` or `statusCode` property is a string, it will be parsed as an number before continuing.

In any of the following scenarios, the function will return a default status code of `500`:

  * The error is not an error object or a plain JavaScript object
  * The error status property is less than `400` or greater than `599`
  * The error status property is a decimal
  * The error status property is a non-numeric string

### `isErrorHttpStatus`

This library exposes a second method named `isErrorHttpStatus`. You can use this to determine whether a given value is a valid error HTTP status (integer, `400` to `599`):

```js
import { isErrorHttpStatus } from '@rowanmanning/get-error-http-status';

isErrorHttpStatus(500); // true
isErrorHttpStatus(200); // false
isErrorHttpStatus('abc'); // false
```

## Migration

A new major version of this project is released if breaking changes are introduced. We maintain a [migration guide](docs/migration.md) to help users migrate between these versions.


## Contributing

[The contributing guide is available here](docs/contributing.md). All contributors must follow [this library's code of conduct](docs/code_of_conduct.md).


## License

Licensed under the [MIT](LICENSE) license.<br/>
Copyright &copy; 2024, Rowan Manning

---
_Source: https://npm.io/package/@rowanmanning/get-error-http-status · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
