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
Copy file name to clipboardExpand all lines: README.md
+58Lines changed: 58 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -118,6 +118,7 @@ Example:
118
118
"host": "https://www.mydomain.com",
119
119
"enable": true,
120
120
"handleErrors": true,
121
+
"errorStackInResponse": false,
121
122
"exclude": [
122
123
{"model": "comment"},
123
124
{"methods": "find"},
@@ -201,6 +202,24 @@ out of the box with EmberJS.
201
202
- Type: `boolean`
202
203
- Default: `true`
203
204
205
+
### errorStackInResponse
206
+
Along handleErrors, When true, this option will send the error stack if available within the error
207
+
response. It will be stored under the `source.stack` key.
208
+
209
+
**Please be careful, this option should never be enabled in a production environment. Doing so can expose sensitive data.**
210
+
211
+
#### example
212
+
```js
213
+
{
214
+
...
215
+
"errorStackInResponse":NODE_ENV==='development',
216
+
...
217
+
}
218
+
```
219
+
220
+
- Type: `boolean`
221
+
- Default: `false`
222
+
204
223
### exclude
205
224
Allows blacklisting of models and methods.
206
225
Define an array of blacklist objects. Blacklist objects can contain "model" key
@@ -419,6 +438,45 @@ module.exports = function (MyModel) {
419
438
}
420
439
```
421
440
441
+
## Custom Errors
442
+
Generic errors respond with a 500, but sometimes you want to have a better control over the error that is returned to the client, taking advantages of fields provided by JSONApi.
443
+
444
+
**It is recommended that you extend the base Error constructor before throwing errors. Eg. BadRequestError**
445
+
446
+
`meta` and `source` fields needs to be objects.
447
+
448
+
#### example
449
+
```js
450
+
module.exports=function (MyModel) {
451
+
MyModel.find=function () {
452
+
var err =newError('April 1st, 1998');
453
+
454
+
err.status=418;
455
+
err.name='I\'m a teapot';
456
+
err.source= { model:'Post', method:'find' };
457
+
err.detail='April 1st, 1998';
458
+
err.code='i\'m a teapot';
459
+
err.meta= { rfc:'RFC2324' };
460
+
461
+
throw err
462
+
}
463
+
}
464
+
465
+
// This will be returned as :
466
+
// {
467
+
// errors: [
468
+
// {
469
+
// status: 418,
470
+
// meta: { rfc: 'RFC2324' },
471
+
// code: 'i\'m a teapot',
472
+
// detail: 'April 1st, 1998',
473
+
// title: 'I\'m a teapot',
474
+
// source: { model: 'Post', method: 'find' }
475
+
// }
476
+
// ]
477
+
// }
478
+
```
479
+
422
480
##### function parameters
423
481
424
482
-`options` All config options set for the deserialization process.
0 commit comments