Skip to content

Commit

Permalink
Make invalid schema message more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
gloooor committed Sep 21, 2021
1 parent e38f292 commit 5583948
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/config/koa.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ const routeErrorHandler = async (ctx, next) => {
const status = error.status || 500;
const errors = error.errors || error.message;

const errorDetails = errors.match('details":\\[(.*)\\]}');
ctx.status = status;

ctx.body = process.env.APP_ENV === 'production'
? { errors: error.errors || { _global: ['Something went wrong.'] } }
: { errors: error.errors || { _global: [error.message] } };
: { errors: error.errors || { _global: errorDetails ? [JSON.parse(errorDetails[1])?.message] : [error.message] } };

logger.error(errors);
}
Expand Down
2 changes: 1 addition & 1 deletion src/middlewares/attachThrowError.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const attachThrowError = async (ctx, next) => {
};

ctx.assertError = (condition, errors = ['Something went wrong.'], status = 400) => {
ctx.assert(condition, status, errors);
ctx.assert(!condition, status, errors);

return null;
};
Expand Down

0 comments on commit 5583948

Please sign in to comment.