Repository navigation
Expand file tree
/
Copy pathmethods.js
More file actions
60 lines (54 loc) · 2.42 KB
/
Copy pathmethods.js
File metadata and controls
60 lines (54 loc) · 2.42 KB
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
50
51
52
53
54
55
56
57
58
59
60
/**
* @file methods.js
* @summary Contains utility methods for throwing errors
* */
const { AppError } = require("./appError");
const { constants } = require(__basedir + "/config");
const { ERROR, LOG_LEVELS } = constants;
/**
* Method for throwing "un-authenticated" error
* @param {string} message Error message
* @param {boolean} [isOperational] Determines whether our app throws error intentionally or its unhandled rejection. Default true
* */
const throwUnAuthenticatedError = (message, isOperational = true) => {
throw new AppError(LOG_LEVELS.ERROR, ERROR.UNAUTHENTICATED.TYPE, message, ERROR.UNAUTHENTICATED.CODE, isOperational);
};
/**
* Method for throwing "bad request" error
* @param {string} message Error message
* @param {boolean} [isOperational] Determines whether our app throws error intentionally or its unhandled rejection. Default true
* */
const throwBadRequestError = (message, isOperational = true) => {
throw new AppError(LOG_LEVELS.ERROR, ERROR.BAD_REQUEST.TYPE, message, ERROR.BAD_REQUEST.CODE, isOperational);
};
/**
* Method for throwing "not found" error
* @param {string} message Error message
* @param {boolean} [isOperational] Determines whether our app throws error intentionally or its unhandled rejection. Default true
* */
const throwNotFoundError = (message, isOperational = true) => {
throw new AppError(LOG_LEVELS.ERROR, ERROR.NOT_FOUND.TYPE, message, ERROR.NOT_FOUND.CODE, isOperational);
};
/**
* Method for throwing "un-authorized" error
* @param {string} message Error message
* @param {boolean} [isOperational] Determines whether our app throws error intentionally or its unhandled rejection. Default true
* */
const throwUnAuthorizedError = (message, isOperational = true) => {
throw new AppError(LOG_LEVELS.ERROR, ERROR.UNAUTHORIZED.TYPE, message, ERROR.UNAUTHORIZED.CODE, isOperational);
};
/**
* Method for throwing "internal error" error
* @param {string} message Error message
* @param {boolean} [isOperational] Determines whether our app throws error intentionally or its unhandled rejection. Default true
* */
const throwInternalServerError = (message, isOperational = true) => {
throw new AppError(LOG_LEVELS.ERROR, ERROR.INTERNAL_SERVER_ERROR.TYPE, message, ERROR.INTERNAL_SERVER_ERROR.CODE, isOperational);
};
module.exports = {
throwBadRequestError,
throwInternalServerError,
throwUnAuthenticatedError,
throwUnAuthorizedError,
throwNotFoundError
};