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