You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Creates error class with the `name` provided, that will throw error with `message`. When `baseType` class provided, new error class will be extending base one, if not `Error` class is extended. Each error generated with this helper will have specific structure and [constructor](#customerror).
**Returns**: <code>{ code, message, stack, data }</code>
78
+
Created error class will throw error instance with [`message`](#createclass) provided in class constructor.
79
+
Field `data` has `any` type. So you can pass there everything.
41
80
42
-
| Param | Type | Description |
43
-
| --- | --- | --- |
44
-
| error | <code>Error</code> | Any error created with [generateFromList](#generateFromList)|
81
+
You can pass an error as second param and it will be saved as cause of current error. See [examples](/examples/generateFromList.js) for more information.
45
82
83
+
<aname="createlist"></a>
84
+
### createErrorsList(list, extend)
85
+
Generates object of errors from object of definitions.
86
+
If no `extend` class provided error classes are extended from `Error`.
Recursively gets stacks from `causedBy` errors and return `Array` of them.
58
132
59
-
| Param | Type | Description |
60
-
| --- | --- | --- |
61
-
| list | <code>Object</code> | Object that define errors. |
62
-
| extend | <code>AnyErrorType</code> | Class that will all generated errors extend. |
63
-
| customFields | <code>Array\<String\></code> | Additional fields that each error will have. Objects will contain fields as props of an object. Default `['data']`|
64
-
| getErr | <code>Function(AnyErrorType)</code> | Function that generate object from error. Default: [getError](#getError)|
133
+
**Returns**: `Array\<String>`
65
134
135
+
| Param | Type | Description | Optional |
136
+
| --- | --- | --- | --- |
137
+
| error |`CustomError`| CustomError | no |
66
138
67
-
<aname="inner"></a>
68
-
### inner(error, ErrorClass)
139
+
<aname="haserrorclass"></a>
140
+
### helpers.hasErrorClass(error, ErrorClass)
69
141
70
-
Check if error has any inner errors with ErrorClass.
142
+
Looks for `ErrorClass` in `error`. Recursivly looks in `causedBy` fields.
143
+
Returns `true` if an instance of `ErrorClass` is found, `false` otherwise.
71
144
72
-
**Returns**: <code>Boolean</code>
73
145
74
-
| Param | Type | Description |
75
-
| --- | --- | --- |
76
-
| error | <code>Error</code> | Any error created with [generateFromList](#generateFromList)|
77
-
| ErrorClass | <code>Error</code> | Any Error from Node or current lib. |
146
+
**Returns**: `Boolean`
78
147
79
-
<aname="lib"></a>
80
-
### lib
148
+
| Param | Type | Description | Optional |
149
+
| --- | --- | --- | --- |
150
+
| error |`CustomError`| Where to look for class. | no |
151
+
| ErrorClass |`AnotherCustomError`| What class to look for. | no |
81
152
82
-
This lib points to [node-common-errors](https://github.com/shutterstock/node-common-errors)
0 commit comments