# https-error-legacy

> Provides the HttpsError class and associated factory methods.

Latest version **1.0.2** (published 2017-11-20) · MIT license · 0 weekly downloads

## Install

```sh
npm install https-error-legacy
pnpm add https-error-legacy
yarn add https-error-legacy
bun add https-error-legacy
```

## Health

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

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2017-11-20 |
| First published | 2017-11-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Frank Hellwig |
| Maintainers | _platekun |
| Keywords | HTTPS, Error |

## Links

- npm: https://www.npmjs.com/package/https-error-legacy
- Repository: https://github.com/Platekun/https-error
- Homepage: https://github.com/Platekun/https-error#README.md
- Issues: https://github.com/fhellwig/https-error/issues
- npm.io page: https://npm.io/package/https-error-legacy

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

- 1.0.2 (latest) — 2017-11-20

## README

# https-error

Provides the `HttpsError` class and associated factory methods.

Version 1.0.2

## Usage

```
$ npm install --save https-error
```

```javascript
var HttpsError = require('https-error');

function sqrt(val) {
	if (val < 0) {
	    throw HttpsError.badRequest('Value %d cannot be negative.', val);
	} else {
	    return Math.sqrt(val);
    }
}

var err = HttpsError.internalServerError('Cannot connect to the database.');

console.log(err.toString());
// Error: 500 (Internal Server Error) Cannot connect to the database.

console.log(err.toJson());
// Outputs an object.

console.log(err.toHtml());
// Outputs an HTML string.
```

The `badRequest` method and `internalServerError` method are factory methods. No `new` keyword is required. There is one factory method for each of the 400- and 500-series errors.

If you want to call the constructor yourself, you can:

```javascript
function sqrt(val) {
	if (val < 0) {
	    throw new HttpsError(400, util.format('Value %d cannot be negative.', val));
	} else {
	    return Math.sqrt(val);
    }
}
```

As you can see, using the factory method...

- is more readable,
- does not require the `new` keyword,
- handles `util.format` arguments.

You can also pass in an `Error` object...

```javascript
var err = new Error('That record already exists.');

var conflict = HttpsError.conflict(err);

console.log(conflict.toString());
// Error: 409 (Conflict) That record already exists.
```

This is useful when wrapping a library error into an error for your REST API.

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