From 7dd4180fba5a4e3de19e221d206f187fd8e3dfda Mon Sep 17 00:00:00 2001 From: syuilo Date: Sat, 23 Feb 2019 15:45:03 +0900 Subject: [PATCH] Better error handling --- src/server/api/api-handler.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/server/api/api-handler.ts b/src/server/api/api-handler.ts index 0fe499489..827aecdf2 100644 --- a/src/server/api/api-handler.ts +++ b/src/server/api/api-handler.ts @@ -13,7 +13,15 @@ export default (endpoint: IEndpoint, ctx: Koa.BaseContext) => new Promise((res) ctx.status = 204; } else if (typeof x === 'number') { ctx.status = x; - ctx.body = { error: y }; + ctx.body = { + error: { + message: y.message, + code: y.code, + id: y.id, + kind: y.kind, + ...(y.info ? { info: y.info } : {}) + } + }; } else { ctx.body = x; }