Skip to content

Commit

Permalink
Merge pull request #98 from oscarArismendi/bugfix/improve-controller-…
Browse files Browse the repository at this point in the history
…error-handling

fix: improve error handling for controllers
  • Loading branch information
mrrishimeena authored Sep 20, 2024
2 parents 007f1ac + 6399dc6 commit 9a75ceb
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 64 deletions.
30 changes: 15 additions & 15 deletions lib/main/server/controllers/appController.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ exports.checkUpdates = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -49,7 +49,7 @@ exports.getSlackDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message :'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -111,7 +111,7 @@ exports.addSlackDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -134,7 +134,7 @@ exports.updateSlackDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: err && err.message ? err.message : 'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -173,7 +173,7 @@ exports.updateSlackDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message :'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -206,7 +206,7 @@ exports.deleteSlackDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -228,7 +228,7 @@ exports.getEmailDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message :'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -273,7 +273,7 @@ exports.addEmailDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -296,7 +296,7 @@ exports.updateEmailDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: err && err.message ? err.message : 'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -336,7 +336,7 @@ exports.updateEmailDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -366,7 +366,7 @@ exports.deleteEmailDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -383,7 +383,7 @@ exports.testSlackNotification = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -400,7 +400,7 @@ exports.testEmailNotification = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -421,7 +421,7 @@ exports.getAlertUrlDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -456,7 +456,7 @@ exports.addAlertUrlDetails = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand Down
18 changes: 9 additions & 9 deletions lib/main/server/controllers/logController.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ exports.getLogs = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: 'invalid request'
message: logs.error || 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand All @@ -52,7 +52,7 @@ exports.getLogs = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -69,7 +69,7 @@ exports.getLogsTTL = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: 'invalid request'
message: result.error || 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand All @@ -80,7 +80,7 @@ exports.getLogsTTL = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -100,7 +100,7 @@ exports.updateLogsTTL = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: 'invalid request'
message: result.error || 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand All @@ -120,7 +120,7 @@ exports.updateLogsTTL = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand Down Expand Up @@ -162,7 +162,7 @@ exports.getLogMeta = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand All @@ -183,7 +183,7 @@ exports.getHostnames = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: 'invalid request'
message: result.error || 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand All @@ -197,7 +197,7 @@ exports.getHostnames = async (req, res) => {
errors: [
{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}
]
});
Expand Down
16 changes: 8 additions & 8 deletions lib/main/server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ exports.createUser = async (req, res) => {
} else {
const errorData = [{
error: 'Internal Server Error',
message: 'An internal server error occurred'
message: createUserResult && createUserResult.error ? createUserResult.error : 'An internal server error occurred'
}];
res.status(500).send({ errors: errorData });
}
Expand All @@ -58,7 +58,7 @@ exports.createUser = async (req, res) => {
res.status(500).send({
errors: [{
error: 'Internal Server Error',
message: 'An unexpected error occurred'
message: error && error.message ? error.message : 'An unexpected error occurred'
}]
});
}
Expand Down Expand Up @@ -93,7 +93,7 @@ exports.loginUser = async (req, res) => {
} else {
const errorData = [{
error: 'Unauthorized',
message: 'Login failed, please check your credentials'
message: verifyUserResult && verifyUserResult.error ? verifyUserResult.error : 'Login failed, please check your credentials'
}];
res.status(401).send({ errors: errorData });
}
Expand All @@ -120,7 +120,7 @@ exports.getUserProfile = async (req, res) => {
} else {
const errorData = [{
error: 'Internal Server Error',
message: 'An internal server error occurred'
message: userDetailsResult && userDetailsResult.error ? userDetailsResult.error : 'An internal server error occurred'
}];
res.status(500).send({ errors: errorData });
}
Expand Down Expand Up @@ -156,7 +156,7 @@ exports.updateUserProfile = async (req, res) => {
} else {
const errorData = [{
error: 'Internal Server Error',
message: 'An internal server error occurred'
message: userDetailsResult && userDetailsResult.error ? userDetailsResult.error : 'An internal server error occurred'
}];
res.status(500).send({ errors: errorData });
}
Expand Down Expand Up @@ -191,7 +191,7 @@ exports.updateUserPassword = async (req, res) => {
} else {
const errorData = [{
error: 'Internal Server Error',
message: 'An internal server error occurred'
message: userDetailsResult && userDetailsResult.message ? userDetailsResult.message : 'An internal server error occurred'
}];
res.status(500).send({ errors: errorData });
}
Expand Down Expand Up @@ -260,7 +260,7 @@ exports.addUser = async (req, res) => {
} else {
const errorData = [{
error: 'Forbidden',
message: 'Not allowed'
message: userDetails.error ||'Not allowed'
}];
res.status(403).send({ errors: errorData });
}
Expand Down Expand Up @@ -301,7 +301,7 @@ exports.removeUser = async (req, res) => {
} else {
const errorData = [{
error: 'Forbidden',
message: 'Not allowed'
message: userDetails.error || 'Not allowed'
}];
res.status(403).send({ errors: errorData });
}
Expand Down
Loading

0 comments on commit 9a75ceb

Please sign in to comment.