Skip to content
Snippets Groups Projects
Commit 9f4898db authored by aurieh's avatar aurieh
Browse files

Clean up, fix things

parent c4cae1d0
No related branches found
No related tags found
No related merge requests found
{ {
"extends": "standard", "extends": "standard",
"parserOptions": {
"ecmaVersion": 6
},
"installedESLint": true, "installedESLint": true,
"plugins": [ "plugins": [
"standard", "standard",
......
...@@ -15,13 +15,34 @@ for (let env of [ ...@@ -15,13 +15,34 @@ for (let env of [
// Create Koa app // Create Koa app
const app = koa(); const app = koa();
const route = require("koa-route"); const route = require('koa-route');
// Error handler
app.use(function* (next) {
try {
yield next;
} catch (err) {
if (err.isBoom) {
this.status = err.output.statusCode || 500;
this.body = err.output.payload || '';
this.set('content-type', 'application/json; charset=utf-8');
for (const header in err.output.headers || {}) {
this.set(header, err.output.headers[header]);
}
} else {
this.status = err.status || 500;
this.body = err.message || '';
}
if (this.status > 499) this.app.emit('error', err, this);
}
});
/** /**
* Parse request body. * Parse request body.
*/ */
app.use(next => { app.use(function* (next) {
if (req.method === 'GET' || req.method === 'DELETE') { if (this.req.method === 'GET' || this.req.method === 'DELETE') {
yield next; yield next;
return; return;
} }
...@@ -43,7 +64,7 @@ app.use(next => { ...@@ -43,7 +64,7 @@ app.use(next => {
this.req.on('end', () => { this.req.on('end', () => {
try { try {
this.req.body = JSON.parse(rawData); this.req.body = JSON.parse(rawData);
yield next; next();
return; return;
} catch (err) { } catch (err) {
this.body = { this.body = {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment