base: Fix logging of sql parameter errors

This commit is contained in:
Jonatan Nilsson 2023-11-30 04:13:08 +00:00
parent bdeeff3794
commit 3a6996bfbb
4 changed files with 11 additions and 4 deletions

View file

@ -33,7 +33,10 @@ export function initPool(core, config) {
if (err.lineNumber && err.procName) { if (err.lineNumber && err.procName) {
message = `Error at ${err.procName}:${err.lineNumber} => ${message}` message = `Error at ${err.procName}:${err.lineNumber} => ${message}`
} }
throw new HttpErrorInternal(message, err) throw new HttpErrorInternal(message, err, !err.lineNumber ? {
name,
params
} : null)
}) })
}, },
promises: pool.promises, promises: pool.promises,

View file

@ -1,7 +1,7 @@
import { HttpError } from 'flaska' import { HttpError } from 'flaska'
export class HttpErrorInternal extends HttpError { export class HttpErrorInternal extends HttpError {
constructor(message, inner) { constructor(message, inner, extra) {
super(500, message); super(500, message);
Error.captureStackTrace(this, HttpError); Error.captureStackTrace(this, HttpError);
@ -10,5 +10,6 @@ export class HttpErrorInternal extends HttpError {
proto.name = 'HttpErrorInternal'; proto.name = 'HttpErrorInternal';
this.inner = inner this.inner = inner
this.extra = extra
} }
} }

View file

@ -54,6 +54,9 @@ export default class Server {
ctx.log.warn(err.message) ctx.log.warn(err.message)
} else { } else {
ctx.log.error(err.inner || err) ctx.log.error(err.inner || err)
if (err.extra) {
ctx.log.error({ extra: err.extra }, 'Database parameters')
}
ctx.status = 500 ctx.status = 500
} }
ctx.body = { ctx.body = {

View file

@ -23,11 +23,11 @@ export function decode(base64StringUrlSafe) {
export function parseMediaAndBanner(item) { export function parseMediaAndBanner(item) {
if (item.banner_path) { if (item.banner_path) {
item.banner_path = 'https://cdn.nfp.is' + item.banner_path item.banner_path = 'https://cdn.nfp.is' + item.banner_path
item.banner_alt_prefix = 'https://cdn.nfp.is' + item.banner_alt_prefix item.banner_alt_prefix = 'https://cdn.nfp.is' + (item.banner_alt_prefix || '')
} }
if (item.media_path) { if (item.media_path) {
item.media_path = 'https://cdn.nfp.is' + item.media_path item.media_path = 'https://cdn.nfp.is' + item.media_path
item.media_alt_prefix = 'https://cdn.nfp.is' + item.media_alt_prefix item.media_alt_prefix = 'https://cdn.nfp.is' + (item.media_alt_prefix || '')
} }
} }