source: trip-planner-front/node_modules/err-code/README.md@ 8d391a1

Last change on this file since 8d391a1 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 2.4 KB
Line 
1# err-code
2
3[![NPM version][npm-image]][npm-url] [![Downloads][downloads-image]][npm-url] [![Build Status][travis-image]][travis-url] [![Dependency status][david-dm-image]][david-dm-url] [![Dev Dependency status][david-dm-dev-image]][david-dm-dev-url] [![Greenkeeper badge][greenkeeper-image]][greenkeeper-url]
4
5[npm-url]:https://npmjs.org/package/err-code
6[downloads-image]:http://img.shields.io/npm/dm/err-code.svg
7[npm-image]:http://img.shields.io/npm/v/err-code.svg
8[travis-url]:https://travis-ci.org/IndigoUnited/js-err-code
9[travis-image]:http://img.shields.io/travis/IndigoUnited/js-err-code/master.svg
10[david-dm-url]:https://david-dm.org/IndigoUnited/js-err-code
11[david-dm-image]:https://img.shields.io/david/IndigoUnited/js-err-code.svg
12[david-dm-dev-url]:https://david-dm.org/IndigoUnited/js-err-code?type=dev
13[david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/js-err-code.svg
14[greenkeeper-image]:https://badges.greenkeeper.io/IndigoUnited/js-err-code.svg
15[greenkeeper-url]:https://greenkeeper.io/
16
17Create new error instances with a code and additional properties.
18
19
20## Installation
21
22```console
23$ npm install err-code
24// or
25$ bower install err-code
26```
27
28The browser file is named index.umd.js which supports CommonJS, AMD and globals (errCode).
29
30
31## Why
32
33I find myself doing this repeatedly:
34
35```js
36var err = new Error('My message');
37err.code = 'SOMECODE';
38err.detail = 'Additional information about the error';
39throw err;
40```
41
42
43## Usage
44
45Simple usage.
46
47```js
48var errcode = require('err-code');
49
50// fill error with message + code
51throw errcode(new Error('My message'), 'ESOMECODE');
52// fill error with message + code + props
53throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' });
54// fill error with message + props
55throw errcode(new Error('My message'), { detail: 'Additional information about the error' });
56```
57
58## Pre-existing fields
59
60If the passed `Error` already has a `.code` field, or fields specified in the third argument to `errcode` they will be overwritten, unless the fields are read only or otherwise throw during assignment in which case a new object will be created that shares a prototype chain with the original `Error`. The `.stack` and `.message` properties will be carried over from the original error and `.code` or any passed properties will be set on it.
61
62
63## Tests
64
65`$ npm test`
66
67
68## License
69
70Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
Note: See TracBrowser for help on using the repository browser.