mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-08-08 07:35:44 +08:00
Merge pull request #2748 from chakflying/feat/improve-err-code
Feat: Use error message to detect and set status code
This commit is contained in:
@@ -739,15 +739,27 @@ exports.filterAndJoin = (parts, connector = "") => {
|
||||
};
|
||||
|
||||
/**
|
||||
* Send a 403 response
|
||||
* Send an Error response
|
||||
* @param {Object} res Express response object
|
||||
* @param {string} [msg=""] Message to send
|
||||
*/
|
||||
module.exports.send403 = (res, msg = "") => {
|
||||
res.status(403).json({
|
||||
"status": "fail",
|
||||
"msg": msg,
|
||||
});
|
||||
module.exports.sendHttpError = (res, msg = "") => {
|
||||
if (msg.includes("SQLITE_BUSY") || msg.includes("SQLITE_LOCKED")) {
|
||||
res.status(503).json({
|
||||
"status": "fail",
|
||||
"msg": msg,
|
||||
});
|
||||
} else if (msg.toLowerCase().includes("not found")) {
|
||||
res.status(404).json({
|
||||
"status": "fail",
|
||||
"msg": msg,
|
||||
});
|
||||
} else {
|
||||
res.status(403).json({
|
||||
"status": "fail",
|
||||
"msg": msg,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
function timeObjectConvertTimezone(obj, timezone, timeObjectToUTC = true) {
|
||||
|
Reference in New Issue
Block a user