Skip to content

Commit 893d672

Browse files
committed
handles internal server error gracefully
1 parent 55d3537 commit 893d672

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

constants/progresses.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED = "Progress document retrieved succe
33
const PROGRESS_DOCUMENT_NOT_FOUND = "No progress records found.";
44
const PROGRESS_ALREADY_CREATED = "Progress for the day has already been created.";
55
const MILLISECONDS_IN_DAY = 24 * 60 * 60 * 1000;
6+
const INTERNAL_SERVER_ERROR_MESSAGE =
7+
"The server has encountered an unexpected error. Please contact the administrator for more information.";
68

79
const RESPONSE_MESSAGES = {
810
PROGRESS_DOCUMENT_CREATED_SUCCEEDED,
@@ -11,4 +13,4 @@ const RESPONSE_MESSAGES = {
1113
PROGRESS_ALREADY_CREATED,
1214
};
1315

14-
module.exports = { RESPONSE_MESSAGES, MILLISECONDS_IN_DAY };
16+
module.exports = { RESPONSE_MESSAGES, MILLISECONDS_IN_DAY, INTERNAL_SERVER_ERROR_MESSAGE };

controllers/progresses.js

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const { Conflict, NotFound } = require("http-errors");
22
const { createProgressDocument, getProgressDocument, getRangeProgressData } = require("../models/progresses");
3-
const { RESPONSE_MESSAGES } = require("../constants/progresses");
3+
const { RESPONSE_MESSAGES, INTERNAL_SERVER_ERROR_MESSAGE } = require("../constants/progresses");
44
const { PROGRESS_DOCUMENT_RETRIEVAL_SUCCEEDED, PROGRESS_DOCUMENT_CREATED_SUCCEEDED } = RESPONSE_MESSAGES;
55

66
/**
@@ -58,8 +58,9 @@ const createProgress = async (req, res) => {
5858
message: error.message,
5959
});
6060
}
61-
return res.status(400).json({
62-
message: error.message,
61+
logger.error(error.message);
62+
return res.status(500).json({
63+
message: INTERNAL_SERVER_ERROR_MESSAGE,
6364
});
6465
}
6566
};
@@ -112,8 +113,9 @@ const getProgress = async (req, res) => {
112113
message: error.message,
113114
});
114115
}
115-
return res.status(400).json({
116-
message: error.message,
116+
logger.error(error.message);
117+
return res.status(500).json({
118+
message: INTERNAL_SERVER_ERROR_MESSAGE,
117119
});
118120
}
119121
};
@@ -165,8 +167,9 @@ const getProgressRangeData = async (req, res) => {
165167
message: error.message,
166168
});
167169
}
168-
return res.status(400).json({
169-
message: error.message,
170+
logger.error(error.message);
171+
return res.status(500).json({
172+
message: INTERNAL_SERVER_ERROR_MESSAGE,
170173
});
171174
}
172175
};

0 commit comments

Comments
 (0)