diff options
Diffstat (limited to 'app/Exceptions/Handler.js')
-rw-r--r-- | app/Exceptions/Handler.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/app/Exceptions/Handler.js b/app/Exceptions/Handler.js new file mode 100644 index 0000000..94d7246 --- /dev/null +++ b/app/Exceptions/Handler.js | |||
@@ -0,0 +1,45 @@ | |||
1 | 'use strict' | ||
2 | |||
3 | const BaseExceptionHandler = use('BaseExceptionHandler') | ||
4 | |||
5 | /** | ||
6 | * This class handles all exceptions thrown during | ||
7 | * the HTTP request lifecycle. | ||
8 | * | ||
9 | * @class ExceptionHandler | ||
10 | */ | ||
11 | class ExceptionHandler extends BaseExceptionHandler { | ||
12 | /** | ||
13 | * Handle exception thrown during the HTTP lifecycle | ||
14 | * | ||
15 | * @method handle | ||
16 | * | ||
17 | * @param {Object} error | ||
18 | * @param {Object} options.request | ||
19 | * @param {Object} options.response | ||
20 | * | ||
21 | * @return {void} | ||
22 | */ | ||
23 | async handle (error, { request, response }) { | ||
24 | if (error.name === 'ValidationException') { | ||
25 | return response.status(400).send('Invalid arguments') | ||
26 | } | ||
27 | |||
28 | response.status(error.status).send(error.message) | ||
29 | } | ||
30 | |||
31 | /** | ||
32 | * Report exception for logging or debugging. | ||
33 | * | ||
34 | * @method report | ||
35 | * | ||
36 | * @param {Object} error | ||
37 | * @param {Object} options.request | ||
38 | * | ||
39 | * @return {void} | ||
40 | */ | ||
41 | async report (error, { request }) { | ||
42 | } | ||
43 | } | ||
44 | |||
45 | module.exports = ExceptionHandler | ||