Skip to content

Commit

Permalink
web > fix error handling status code in prod
Browse files Browse the repository at this point in the history
  • Loading branch information
dsevillamartin committed Mar 3, 2024
1 parent b9eebd9 commit f2adacb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
6 changes: 5 additions & 1 deletion knexfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
9 changes: 4 additions & 5 deletions lib/Web/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down

0 comments on commit f2adacb

Please sign in to comment.