diff --git a/package.json b/package.json index 29d9bbd..0e3aa69 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "koa-bodyparser": "^4.2.1", "koa-joi-router": "^5.1.0", "koa-json": "^2.0.2", + "koa-json-error": "^3.1.2", "koa-logger": "^3.2.0", "lokijs": "^1.5.5", "nunjucks": "^3.1.4" diff --git a/src/app.js b/src/app.js index 6e486c9..9469105 100644 --- a/src/app.js +++ b/src/app.js @@ -1,5 +1,6 @@ import Koa from 'koa' import JSON from 'koa-json' +import JsonError from 'koa-json-error' import JoiRouter from 'koa-joi-router' import BodyParser from 'koa-bodyparser' @@ -7,9 +8,10 @@ const App = (ghc) => { const app = new Koa() const router = new JoiRouter() - app.use(router.middleware()) + app.use(JSON({pretty: true})) + .use(JsonError()) + .use(router.middleware()) .use(BodyParser({onerror:console.error})) - .use(JSON({pretty: true})) app.on('error', (err, ctx) => { console.error('server error', err, ctx)