• Home
Name
Date
Size
#Lines
LOC

..--

test/12-May-2024-9877

.editorconfigD12-May-2024179 1310

.eslintrc.jsonD12-May-2024127 77

.npmignoreD12-May-202425 32

.travis.ymlD12-May-202454 65

README.mdD12-May-20242.3 KiB7347

bower.jsonD12-May-2024589 3130

index.jsD12-May-2024397 2317

index.umd.jsD12-May-20241.2 KiB2620

package.jsonD12-May-20241.7 KiB6564

README.md

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]
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#info=devDependencies
13 [david-dm-dev-image]:https://img.shields.io/david/dev/IndigoUnited/js-err-code.svg
14 
15 Create new error instances with a code and additional properties.
16 
17 
18 ## Installation
19 
20 `$ npm install err-code` - `NPM`
21 `$ bower install err-code` - `bower`
22 
23 The browser file is named index.umd.js which supports CommonJS, AMD and globals (errCode).
24 
25 
26 ## Why
27 
28 I find myself doing this repeatedly:
29 
30 ```js
31 var err = new Error('My message');
32 err.code = 'SOMECODE';
33 err.detail = 'Additional information about the error';
34 throw err;
35 ```
36 
37 
38 ## Usage
39 
40 Simple usage.
41 
42 ```js
43 var errcode = require('err-code');
44 
45 // fill error with message + code
46 throw errcode(new Error('My message'), 'ESOMECODE');
47 // fill error with message + code + props
48 throw errcode(new Error('My message'), 'ESOMECODE', { detail: 'Additional information about the error' });
49 // fill error with message + props
50 throw errcode(new Error('My message'), { detail: 'Additional information about the error' });
51 
52 
53 // You may also pass a string in the first argument and an error will be automatically created
54 // for you, though the stack trace will contain err-code in it.
55 
56 // create error with message + code
57 throw errcode('My message', 'ESOMECODE');
58 // create error with message + code + props
59 throw errcode('My message', 'ESOMECODE', { detail: 'Additional information about the error' });
60 // create error with message + props
61 throw errcode('My message', { detail: 'Additional information about the error' });
62 ```
63 
64 
65 ## Tests
66 
67 `$ npm test`
68 
69 
70 ## License
71 
72 Released under the [MIT License](http://www.opensource.org/licenses/mit-license.php).
73