From f2adacbc4ca9b1b1845661eb388fcca69d51076a Mon Sep 17 00:00:00 2001 From: David Sevilla Martin <6401250+dsevillamartin@users.noreply.github.com> Date: Sun, 3 Mar 2024 15:36:01 -0500 Subject: [PATCH] web > fix error handling status code in prod --- knexfile.js | 6 +++++- lib/Web/index.js | 9 ++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/knexfile.js b/knexfile.js index 820611d..ec513d2 100644 --- a/knexfile.js +++ b/knexfile.js @@ -7,7 +7,11 @@ module.exports = { }, pool: { min: 2, - max: 10 + max: 10, + afterCreate: (db, done) => { + // db is a better-sqlite3 Database instance + db(); + } }, migrations: { tableName: 'migrations', diff --git a/lib/Web/index.js b/lib/Web/index.js index 76538a3..c3de2fc 100644 --- a/lib/Web/index.js +++ b/lib/Web/index.js @@ -491,18 +491,17 @@ app.use((err, req, res, next) => { const isDev = req.app.get('env') === 'development'; - if (isDev) { - res.status(status || 500); - } + res.status(status || 500); const payload = { name: err.name, message: err.message, - stack: isDev && err.stack, - status: (isDev && status) || 500, + status: status || 500, sentry: res.sentry, }; + if (isDev && err.stack) payload.stack = err.stack; + res.format({ json: () => res.json(payload), html: () => res.render('error', payload),