Skip to content

Commit

Permalink
refactor: handled each cases in error response
Browse files Browse the repository at this point in the history
  • Loading branch information
mrrishimeena committed Sep 24, 2024
1 parent 078ee74 commit 853035d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
8 changes: 4 additions & 4 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: logs.error || 'invalid request'
message: (logs && logs.error) ? logs.error : 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand Down Expand Up @@ -69,7 +69,7 @@ exports.getLogsTTL = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: result.error || 'invalid request'
message: (result && result.error) ? result.error : 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand Down Expand Up @@ -100,7 +100,7 @@ exports.updateLogsTTL = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: result.error || 'invalid request'
message: (result && result.error) ? result.error : 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand Down Expand Up @@ -183,7 +183,7 @@ exports.getHostnames = async (req, res) => {
const errorData = [
{
error: 'Bad Request',
message: result.error || 'invalid request'
message: (result && result.error) ? result.error : 'invalid request'
}
];
res.status(400).send({ errors: errorData });
Expand Down
4 changes: 2 additions & 2 deletions lib/main/server/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ exports.addUser = async (req, res) => {
} else {
const errorData = [{
error: 'Forbidden',
message: userDetails.error || 'Not allowed'
message: (userDetails && userDetails.error) ? 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: userDetails.error || 'Not allowed'
message: (userDetails && userDetails.error) ? userDetails.error : 'Not allowed'
}];
res.status(403).send({ errors: errorData });
}
Expand Down

0 comments on commit 853035d

Please sign in to comment.