-
Notifications
You must be signed in to change notification settings - Fork 0
/
errorHandler.js
38 lines (29 loc) · 960 Bytes
/
errorHandler.js
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
const logger = require('./logger');
const JobError = require('./models/JobError');
function handleError(msg, error) {
if (error.response && error.response.status && error.response.data.errors) {
msg += ` - ${error.response.data.errors[0].message}`;
logger.error(msg, { code: error.response.status, error: error.response.data.errors });
JobError.create({
message: msg,
error: error.response.data.errors,
});
} else {
if (error.message) {
console.log(error);
logger.error(msg, { error: error.message });
JobError.create({
message: msg,
error: error.message,
});
} else {
logger.error(error);
logger.error(msg);
JobError.create({
message: msg,
error: error,
});
}
}
}
module.exports = { handleError };