From 26b9ae22724862fac562052d254e0a2f42fadca5 Mon Sep 17 00:00:00 2001 From: vantezzen Date: Mon, 26 Aug 2019 21:26:59 +0200 Subject: Improve recipe creation --- app/Exceptions/Handler.js | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 app/Exceptions/Handler.js (limited to 'app/Exceptions/Handler.js') 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 @@ +'use strict' + +const BaseExceptionHandler = use('BaseExceptionHandler') + +/** + * This class handles all exceptions thrown during + * the HTTP request lifecycle. + * + * @class ExceptionHandler + */ +class ExceptionHandler extends BaseExceptionHandler { + /** + * Handle exception thrown during the HTTP lifecycle + * + * @method handle + * + * @param {Object} error + * @param {Object} options.request + * @param {Object} options.response + * + * @return {void} + */ + async handle (error, { request, response }) { + if (error.name === 'ValidationException') { + return response.status(400).send('Invalid arguments') + } + + response.status(error.status).send(error.message) + } + + /** + * Report exception for logging or debugging. + * + * @method report + * + * @param {Object} error + * @param {Object} options.request + * + * @return {void} + */ + async report (error, { request }) { + } +} + +module.exports = ExceptionHandler -- cgit v1.2.3-70-g09d2