aboutsummaryrefslogtreecommitdiffstats
path: root/src/internal-server/app/Exceptions/Handler.js
blob: ab323fd3897fe0409d741efb97ba6ff49892db72 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
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.response
   *
   * @return {Promise<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
   *
   * @return {Promise<boolean>}
   */
  async report() {
    return true;
  }
}

module.exports = ExceptionHandler;