From d0ee993d6130dcb66bb73cd4c242dfcb796b69b2 Mon Sep 17 00:00:00 2001 From: Gloria Loi Date: Tue, 7 Sep 2021 17:02:45 +0300 Subject: [PATCH] Make invalid schema message more readable --- src/config/koa.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/config/koa.js b/src/config/koa.js index ec1f045..d74fe50 100644 --- a/src/config/koa.js +++ b/src/config/koa.js @@ -16,9 +16,11 @@ const routeErrorHandler = async (ctx, next) => { ctx.status = error.statusCode || error.status || 500; if (!ctx.body) { + const errorDetails = error.message.match('details":\\[(.*)\\]}'); + ctx.body = { errors: { - _global: [error.message], + _global: errorDetails ? [JSON.parse(errorDetails[1])] : [error.message], }, }; }