From 419933f6505caf4c5e685f8436b1ff735185e55a Mon Sep 17 00:00:00 2001 From: Vijay Raghavan Aravamudhan Date: Sun, 1 Aug 2021 11:07:57 +0000 Subject: Moved 'internal-server' into a sub-folder as opposed to a git submodule. (#1715) * Ignored tests in 'internal-server' folder since there are none. * Linter fixes --- src/internal-server/app/Exceptions/Handler.js | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 src/internal-server/app/Exceptions/Handler.js (limited to 'src/internal-server/app/Exceptions/Handler.js') 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 @@ +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, { response }) { + if (error.name === 'ValidationException') { + return response.status(400).send('Invalid arguments'); + } + + return 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() { + return true; + } +} + +module.exports = ExceptionHandler; -- cgit v1.2.3-54-g00ecf