Skip to content

Commit

Permalink
Merge pull request #613 from Giveth/f_612_server_should_not_return_st…
Browse files Browse the repository at this point in the history
…ack_error

Don't return stack errors to client
  • Loading branch information
aminlatifi authored Sep 14, 2021
2 parents 1c3301f + 75de4fd commit 512390a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/app.hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const convertVerifiedToBoolean = () => context => {
return context;
};

const changeMongoErrors = () => context => {
const parseErrors = () => context => {
// verified field is boolean in Trace, Campaign and Community so for getting this filter
// in query string we should cast it to boolean here
if (context.error.message.includes('Invalid query parameter')) {
Expand All @@ -69,6 +69,11 @@ const changeMongoErrors = () => context => {
logger.info('Mongo error in feathers call', context.error);
throw new errors.BadRequest(errorMessages.INVALID_INPUT_DATA);
}
if (context.error.stack && context.error.type !== 'FeathersError') {
// Should not return stack error to client when error is not instance of Feathers error
logger.info('Error with stack', context.error);
throw new errors.GeneralError();
}
return context;
};

Expand Down Expand Up @@ -123,7 +128,7 @@ module.exports = {
},

error: {
all: [responseLoggerHook(), changeMongoErrors()],
all: [responseLoggerHook(), parseErrors()],
find: [],
get: [],
create: [],
Expand Down

0 comments on commit 512390a

Please sign in to comment.