From 604e05aa02095f54a8e12e86b422a60c51fd0cc5 Mon Sep 17 00:00:00 2001 From: Xiao Gui <xgui3783@gmail.com> Date: Wed, 8 May 2019 15:04:57 +0200 Subject: [PATCH] bugfix: proper error catching in node backend --- deploy/app.js | 6 +++--- deploy/catchError.js | 2 +- deploy/datasets/index.js | 7 +++---- 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/deploy/app.js b/deploy/app.js index f2fb025c6..c7ba75d36 100644 --- a/deploy/app.js +++ b/deploy/app.js @@ -38,9 +38,6 @@ app.use(session({ */ configureAuth(app) -const catchError = require('./catchError') -app.use(catchError) - const publicPath = process.env.NODE_ENV === 'production' ? path.join(__dirname, 'public') : path.join(__dirname, '..', 'dist', 'aot') @@ -61,4 +58,7 @@ app.use('/nehubaConfig', nehubaConfigRouter) app.use('/datasets', datasetRouter) app.use('/plugins', pluginRouter) +const catchError = require('./catchError') +app.use(catchError) + module.exports = app \ No newline at end of file diff --git a/deploy/catchError.js b/deploy/catchError.js index f78a42919..0fdc48434 100644 --- a/deploy/catchError.js +++ b/deploy/catchError.js @@ -7,5 +7,5 @@ module.exports = ({code = 500, error = 'an error had occured', trace = 'undefine error, trace }) - res.sendStatus(code) + res.status(code).send() } \ No newline at end of file diff --git a/deploy/datasets/index.js b/deploy/datasets/index.js index 01a7925bf..0806d7048 100644 --- a/deploy/datasets/index.js +++ b/deploy/datasets/index.js @@ -18,8 +18,7 @@ datasetsRouter.get('/templateName/:templateName', (req, res, next) => { const { user } = req getDatasets({ templateName, user }) .then(ds => { - const data = JSON.stringify(ds) - res.status(200).send(data) + res.status(200).json(ds) }) .catch(error => { next({ @@ -35,7 +34,7 @@ datasetsRouter.get('/parcellationName/:parcellationName', (req, res, next) => { const { user } = req getDatasets({ parcellationName, user }) .then(ds => { - res.status(200).send(JSON.stringify(ds)) + res.status(200).json(ds) }) .catch(error => { next({ @@ -51,7 +50,7 @@ datasetsRouter.get('/preview/:datasetName', (req, res, next) => { getPreview({ datasetName }) .then(preview => { if (preview) { - res.status(200).send(JSON.stringify(preview)) + res.status(200).json(preview) } else { next({ code: 404, -- GitLab