Use response handler in handleErrors middleare

This commit is contained in:
Alex Holliday committed 2025-01-19 20:14:03 -08:00
1 parent e9eadfe838
commit 9f43336a03
4 files changed
+11 -5

No files matched your search

+4 -1
View File
@@ -153,7 +153,9 @@ class AuthController {
// Compare password // Compare password
const match = await user.comparePassword(password); const match = await user.comparePassword(password);
if (match !== true) { if (match !== true) {
next(new Error(errorMessages.AUTH_INCORRECT_PASSWORD)); const error = new Error(errorMessages.AUTH_INCORRECT_PASSWORD);
error.status = 401;
next(error);
return; return;
} }
@@ -182,6 +184,7 @@ class AuthController {
}, },
}); });
} catch (error) { } catch (error) {
error.status = 401;
next(handleError(error, SERVICE_NAME, "loginUser")); next(handleError(error, SERVICE_NAME, "loginUser"));
} }
}; };
+1 -1
View File
@@ -34,7 +34,7 @@ class SettingsController {
await this.db.updateAppSettings(req.body); await this.db.updateAppSettings(req.body);
const updatedSettings = { ...(await this.settingsService.reloadSettings()) }; const updatedSettings = { ...(await this.settingsService.reloadSettings()) };
delete updatedSettings.jwtSecret; delete updatedSettings.jwtSecret;
return res.successs({ return res.success({
msg: successMessages.UPDATE_APP_SETTINGS, msg: successMessages.UPDATE_APP_SETTINGS,
data: updatedSettings, data: updatedSettings,
}); });
+4 -1
View File
@@ -11,7 +11,10 @@ const handleErrors = (error, req, res, next) => {
method: error.method, method: error.method,
stack: error.stack, stack: error.stack,
}); });
res.status(status).json({ success: false, msg: message }); res.error({
status,
msg: message,
});
}; };
export { handleErrors }; export { handleErrors };
+2 -2
View File
@@ -7,8 +7,8 @@ const responseHandler = (req, res, next) => {
}); });
}; };
res.error = (status = 500, msg = "Internal server erro", data = null) => { res.error = ({ status = 500, msg = "Internal server erro", data = null }) => {
res.status(status).json({ return res.status(status).json({
success: false, success: false,
msg, msg,
data, data,