# @senhung/http-exceptions

> ⚠️ Http server side error exceptions

Latest version **1.1.1** (published 2018-07-30) · MIT license · 0 weekly downloads

## Install

```sh
npm install @senhung/http-exceptions
pnpm add @senhung/http-exceptions
yarn add @senhung/http-exceptions
bun add @senhung/http-exceptions
```

## Health

**Score 25/100 (F)** — status: abandoned.

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

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2018-07-30 |
| First published | 2018-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 57 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 2 |
| Author | Senhung Wong |
| Maintainers | senhung |
| Keywords | http, exceptions, server-side-error, http-exceptions, restful, rest, http-server-exceptions |

## Links

- npm: https://www.npmjs.com/package/@senhung/http-exceptions
- Repository: https://github.com/senhungwong/http-exceptions
- Homepage: https://github.com/senhungwong/http-exceptions#readme
- Issues: https://github.com/senhungwong/http-exceptions/issues
- npm.io page: https://npm.io/package/@senhung/http-exceptions

## Alternatives

- [launchdarkly-js-client-sdk](https://npm.io/package/launchdarkly-js-client-sdk.md) — 2.5M weekly downloads
- [@elastic/elasticsearch](https://npm.io/package/@elastic/elasticsearch.md) — 2.1M weekly downloads
- [@c8y/client](https://npm.io/package/@c8y/client.md) — 15.3K weekly downloads
- [@signaldb/maverickjs](https://npm.io/package/@signaldb/maverickjs.md) — 1.7K weekly downloads
- [@bbc/http-transport-cache](https://npm.io/package/@bbc/http-transport-cache.md) — 1.2K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2018-07-30
- 1.1.0 — 2018-07-29
- 1.0.4 — 2018-07-29
- 1.0.3 — 2018-07-28
- 1.0.2 — 2018-07-28

## README

# Http Exceptions

![Travis (.org)](https://img.shields.io/travis/senhungwong/http-exceptions.svg?style=flat-square)
[![GitHub](https://img.shields.io/github/license/senhungwong/http-exceptions.svg?style=flat-square)](https://opensource.org/licenses/MIT)
[![npm](https://img.shields.io/npm/v/@senhung/http-exceptions.svg?style=flat-square)](https://www.npmjs.com/package/@senhung/http-exceptions)


## Install

```bash
$ npm install @senhung/http-exceptions --save
```

OR

```bash
$ yarn add @senhung/http-exceptions
```

## Example Express.js Usage

```javascript
const HttpExceptions = require('@senhung/http-exceptions');
const express        = require('express');

/* create express app */
const app = express();

/* define an app endpoint */
app.get('/', (req, res) => {
    throw new HttpExceptions.NotImplementedHttpException('This method is not implemented yet');
});

/* handle exceptions generally */
app.use((err, req, res, next) => {
    /* http exceptions handling */
    if (err instanceof HttpExceptions.HttpException) {
        return res.status(err.getStatusCode()).json(err.getMessage() ? {message: err.getMessage()} : {});
    }

    /* other errors */
    res.sandStatus(500);
});
```

OR

```javascript
const HttpExceptions = require('@senhung/http-exceptions');
const express        = require('express');

/* create express router  */
const router = new express.Router();

/* define a route endpoint */
router.get('/', (req, res, next) => {
    return next(new HttpExceptions.NotImplementedHttpException('This method is not implemented yet'));
});

/* create express app */
const app = express();

/* use router */
app.use(router);

/* handle exceptions generally */
app.use((err, req, res, next) => {
    /* http exceptions handling */
    if (err instanceof HttpExceptions.HttpException) {
        return res.status(err.getStatusCode()).json(err.getMessage() ? {message: err.getMessage()} : {});
    }

    /* other errors */
    res.sandStatus(500);
});
```

## Tests

```bash
$ npm test
```

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