source: frontend/node_modules/makeerror/readme.md

Last change on this file was 9af201e, checked in by MBK <marija.karapandzova@…>, 11 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.6 KB
Line 
1makeerror [![Build Status](https://secure.travis-ci.org/nshah/nodejs-makeerror.png)](http://travis-ci.org/nshah/nodejs-makeerror)
2=========
3
4A library to make errors.
5
6
7Basics
8------
9
10Makes an Error constructor function with the signature below. All arguments are
11optional, and if the first argument is not a `String`, it will be assumed to be
12`data`:
13
14```javascript
15function(message, data)
16```
17
18You'll typically do something like:
19
20```javascript
21var makeError = require('makeerror')
22var UnknownFileTypeError = makeError(
23 'UnknownFileTypeError',
24 'The specified type is not known.'
25)
26var er = UnknownFileTypeError()
27```
28
29`er` will have a prototype chain that ensures:
30
31```javascript
32er instanceof UnknownFileTypeError
33er instanceof Error
34```
35
36
37Templatized Error Messages
38--------------------------
39
40There is support for simple string substitutions like:
41
42```javascript
43var makeError = require('makeerror')
44var UnknownFileTypeError = makeError(
45 'UnknownFileTypeError',
46 'The specified type "{type}" is not known.'
47)
48var er = UnknownFileTypeError({ type: 'bmp' })
49```
50
51Now `er.message` or `er.toString()` will return `'The specified type "bmp" is
52not known.'`.
53
54
55Prototype Hierarchies
56---------------------
57
58You can create simple hierarchies as well using the `prototype` chain:
59
60```javascript
61var makeError = require('makeerror')
62var ParentError = makeError('ParentError')
63var ChildError = makeError(
64 'ChildError',
65 'The child error.',
66 { proto: ParentError() }
67)
68var er = ChildError()
69```
70
71`er` will have a prototype chain that ensures:
72
73```javascript
74er instanceof ChildError
75er instanceof ParentError
76er instanceof Error
77```
Note: See TracBrowser for help on using the repository browser.