Add sql trace in error log on sequelize error
This commit is contained in:
parent
d6ca951b3c
commit
328e607d32
3 changed files with 14 additions and 3 deletions
|
@ -166,7 +166,10 @@ app.use(function (err, req, res, next) {
|
||||||
error = err.stack || err.message || err
|
error = err.stack || err.message || err
|
||||||
}
|
}
|
||||||
|
|
||||||
logger.error('Error in controller.', { err: error })
|
// Sequelize error
|
||||||
|
const sql = err.parent ? err.parent.sql : undefined
|
||||||
|
|
||||||
|
logger.error('Error in controller.', { err: error, sql })
|
||||||
return res.status(err.status || 500).end()
|
return res.status(err.status || 500).end()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,13 @@ function loggerReplacer (key: string, value: any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
const consoleLoggerFormat = winston.format.printf(info => {
|
const consoleLoggerFormat = winston.format.printf(info => {
|
||||||
let additionalInfos = JSON.stringify(info.meta || info.err, loggerReplacer, 2)
|
const obj = {
|
||||||
|
meta: info.meta,
|
||||||
|
err: info.err,
|
||||||
|
sql: info.sql
|
||||||
|
}
|
||||||
|
|
||||||
|
let additionalInfos = JSON.stringify(obj, loggerReplacer, 2)
|
||||||
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
|
if (additionalInfos === undefined || additionalInfos === '{}') additionalInfos = ''
|
||||||
else additionalInfos = ' ' + additionalInfos
|
else additionalInfos = ' ' + additionalInfos
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,8 @@ function cacheRoute (lifetimeArg: string | number) {
|
||||||
logger.error('Cannot cache route.', { err })
|
logger.error('Cannot cache route.', { err })
|
||||||
return done(err)
|
return done(err)
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
done()
|
||||||
}
|
}
|
||||||
|
|
||||||
return sendSave(body)
|
return sendSave(body)
|
||||||
|
@ -52,7 +54,7 @@ function cacheRoute (lifetimeArg: string | number) {
|
||||||
return done()
|
return done()
|
||||||
})
|
})
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
logger.error('Cannot serve cached route.', err)
|
logger.error('Cannot serve cached route.', { err })
|
||||||
return next()
|
return next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue