diff options
Diffstat (limited to 'src/internal-server/app/Exceptions/Handler.js')
-rw-r--r-- | src/internal-server/app/Exceptions/Handler.js | 40 |
1 files changed, 40 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..ab323fd38 --- /dev/null +++ b/src/internal-server/app/Exceptions/Handler.js | |||
@@ -0,0 +1,40 @@ | |||
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.response | ||
17 | * | ||
18 | * @return {Promise<void>} | ||
19 | */ | ||
20 | async handle(error, { response }) { | ||
21 | if (error.name === 'ValidationException') { | ||
22 | return response.status(400).send('Invalid arguments'); | ||
23 | } | ||
24 | |||
25 | return response.status(error.status).send(error.message); | ||
26 | } | ||
27 | |||
28 | /** | ||
29 | * Report exception for logging or debugging. | ||
30 | * | ||
31 | * @method report | ||
32 | * | ||
33 | * @return {Promise<boolean>} | ||
34 | */ | ||
35 | async report() { | ||
36 | return true; | ||
37 | } | ||
38 | } | ||
39 | |||
40 | module.exports = ExceptionHandler; | ||