-
Notifications
You must be signed in to change notification settings - Fork 0
/
errors.js
29 lines (25 loc) · 910 Bytes
/
errors.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
const errors = {
400: "The request object is missing at least one of the required attributes",
401: "Invalid token.",
403: {
unauthorized: "You do not have access to this truck",
loadAlreadyAssigned: "The load is already loaded on another truck",
},
404: {
truck: "No truck with this truck_id exists",
load: "No load with this load_id exists",
either:
"No truck with this truck_id is loaded with the load with this load_id",
},
405: "This endpoint is not supported",
406: "This application only supports JSON responses",
415: "Server only accepts application/json data.",
};
function displayErrorMessage(res, statusCode, subcategory = null) {
let errorMsg = errors[statusCode];
if (subcategory) {
errorMsg = errorMsg[subcategory];
}
return res.status(statusCode).json({ Error: errorMsg });
}
module.exports.displayErrorMessage = displayErrorMessage;