Name |
Date |
Size |
#Lines |
LOC |
||
---|---|---|---|---|---|---|
.. | - | - | ||||
test/ | 12-May-2024 | - | 98 | 77 | ||
.editorconfig | D | 12-May-2024 | 179 | 13 | 10 | |
.eslintrc.json | D | 12-May-2024 | 127 | 7 | 7 | |
.npmignore | D | 12-May-2024 | 25 | 3 | 2 | |
.travis.yml | D | 12-May-2024 | 54 | 6 | 5 | |
README.md | D | 12-May-2024 | 2.3 KiB | 73 | 47 | |
bower.json | D | 12-May-2024 | 589 | 31 | 30 | |
index.js | D | 12-May-2024 | 397 | 23 | 17 | |
index.umd.js | D | 12-May-2024 | 1.2 KiB | 26 | 20 | |
package.json | D | 12-May-2024 | 1.7 KiB | 65 | 64 |
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