All files / backend/koa-middleware HttpError.js

100% Statements 7/7
100% Branches 0/0
100% Functions 1/1
100% Lines 7/7
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 41 42 43 44 45 46 47 48 49 501x                                                                             139x   139x 139x 139x 139x       1x  
const uuid = require('uuid/v4');
 
/**
 * @swagger
 * definition:
 *   UserInputError:
 *     description:
 *       HTTP status code 400.
 *       User sent invalid data like URI id.
 *
 *     properties:
 *       errorId:
 *         type: string
 *         format: uuid
 *
 *       errorCode:
 *         type: string
 *         example: INVALID_INPUT_EMAIL
 *
 *       errorMessage:
 *         type: string
 *         example: test@test. is invalid email
 */
 
/**
 * Extends over the global `Error`.
 * This class is used to create errors that have more code related info for easy tracking and
 * have Human readable error reason for direct use in FrontEnd.
 *
 * @category BackEndUtils
 */
class HttpError extends Error {
  /**
   * @param {String} status HTTP status code, example `400`, `401`, `500`
   * @param {String} code Internal error code, example `NOT_IN_GROUP`, `NO_PERMISSION`
   * @param {String} message Human readable reason for the error.
   * @param {any} data Any additional info that needs to be logged
   */
  constructor(status, code, message, data) {
    super(message);
 
    this.id = uuid();
    this.status = status;
    this.code = code;
    this.data = data;
  }
}
 
module.exports = HttpError;