improve error handling with koa-json-error

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2018-12-13 10:34:38 +01:00
parent cc7018a314
commit 6f59c0cda1
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
2 changed files with 5 additions and 2 deletions

View File

@ -12,6 +12,7 @@
"koa-bodyparser": "^4.2.1", "koa-bodyparser": "^4.2.1",
"koa-joi-router": "^5.1.0", "koa-joi-router": "^5.1.0",
"koa-json": "^2.0.2", "koa-json": "^2.0.2",
"koa-json-error": "^3.1.2",
"koa-logger": "^3.2.0", "koa-logger": "^3.2.0",
"lokijs": "^1.5.5", "lokijs": "^1.5.5",
"nunjucks": "^3.1.4" "nunjucks": "^3.1.4"

View File

@ -1,5 +1,6 @@
import Koa from 'koa' import Koa from 'koa'
import JSON from 'koa-json' import JSON from 'koa-json'
import JsonError from 'koa-json-error'
import JoiRouter from 'koa-joi-router' import JoiRouter from 'koa-joi-router'
import BodyParser from 'koa-bodyparser' import BodyParser from 'koa-bodyparser'
@ -7,9 +8,10 @@ const App = (ghc) => {
const app = new Koa() const app = new Koa()
const router = new JoiRouter() const router = new JoiRouter()
app.use(router.middleware()) app.use(JSON({pretty: true}))
.use(JsonError())
.use(router.middleware())
.use(BodyParser({onerror:console.error})) .use(BodyParser({onerror:console.error}))
.use(JSON({pretty: true}))
app.on('error', (err, ctx) => { app.on('error', (err, ctx) => {
console.error('server error', err, ctx) console.error('server error', err, ctx)