# rduk-errors

> Custom Errors library for Node

Latest version **1.2.3** (published 2016-11-27) · MIT license · 0 weekly downloads

## Install

```sh
npm install rduk-errors
pnpm add rduk-errors
yarn add rduk-errors
bun add rduk-errors
```

## 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.2.3 |
| Published | 2016-11-27 |
| First published | 2016-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Kim UNG |
| Maintainers | khuang |
| Keywords | rduk, custom, errors, nodejs |

## Links

- npm: https://www.npmjs.com/package/rduk-errors
- Repository: https://github.com/rd-uk/rduk-errors
- Homepage: https://github.com/rd-uk/rduk-errors#readme
- Issues: https://github.com/rd-uk/rduk-errors/issues
- npm.io page: https://npm.io/package/rduk-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

- 1.2.3 (latest) — 2016-11-27
- 1.2.2 — 2016-11-03
- 1.2.1 — 2016-10-29
- 1.2.0 — 2016-10-29
- 1.1.0 — 2016-10-27
- 1.0.1 — 2016-10-26
- 1.0.0 — 2016-10-26

## README

# RDUK - errors

[![Build Status](https://travis-ci.org/rd-uk/rduk-errors.svg?branch=master)](https://travis-ci.org/rd-uk/rduk-errors)
[![Coverage Status](https://coveralls.io/repos/github/rd-uk/rduk-errors/badge.svg?branch=master)](https://coveralls.io/github/rd-uk/rduk-errors?branch=master)

## Installation

```
npm install rduk-errors --save --save-exact
```

## Usage

```js
var errors = require('rduk-errors');
```

You can instantiate a new error from the available errors. see the [list](#available_errors)

```js
var myarg = 1;

try {
    var err = new errors.ArgumentError('myarg', myarg);
    throw err;
} catch(err) {
    console.log(err instanceof Error); // will output true
    console.log(err instanceof errors.ArgumentError); // will output true
}
```

or throw it directly

```js
try {
    errors.throwArgumentError('myarg', myarg);
} catch(err) {
    console.error(err);
    /**
     * will output:
     * { [ArgumentError: Invalid argument "myarg" (value: "1").]
     *   name: 'ArgumentError',
     *   message: 'Invalid argument "myarg" (value: "1").' }
     */
}
```

You can also add your own custom error

```js

/* FakeError.js */
(function(module) {

    'use strict';

    module.exports = function FakeError(message) {
        FakeError.super_.call(this, message);
    };

} (module));

/* main.js */
var errors = require('rduk-errors');
errors.add('FakeError', require('pathToFakeError/FakeError'));

try {
    errors.throwFakeError('this is a fake error.');
} catch (err) {
    console.log(err instanceof errors.FakeError); // will output true
}

```

By default, your custom error inherits `BaseError`. The `BaseError` class is in charge 
to initialize all error specific properties.

```js
/* BaseError.js */
(function(require, module) {

    'use strict';

    module.exports = function BaseError(message) {
        Error.captureStackTrace(this, this.constructor);

        this.name = this.constructor.name;
        this.message = message;
    };

    require('util').inherits(module.exports, Error);

} (require, module));
```

But you can, if needed, inherit from your own custom error

```js
var errors = require('rduk-errors');

errors.add('ChildFakeError', function ChildFakeError() {
    ChildFakeError.super_.call(this, 'this is a fake error.');
}, errors.FakeError);

try {
    errors.throwChildFakeError();
} catch (err) {
    /* ... */
}
```

<a name="available_errors"></a>
## Available errors
* `errors.ArgumentNullError` ( `propertyName` );
* `errors.ArgumentError` ( `propertyName` , `propertyValue` );
* `errors.ArgumentOutOfRangeError` ( `propertyName` );
* `errors.ConfigurationError` ( `message` );
* `errors.NotImplementedError` ( `methodName` );
* `errors.NotSupportedError` ( `methodName` );

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