mirror of
https://github.com/IT4Change/gradido.git
synced 2026-02-06 09:56:05 +00:00
more precise error logging
This commit is contained in:
parent
f54b4e67d1
commit
75ed95a548
@ -28,11 +28,11 @@ async function main() {
|
||||
`GraphIQL available at ${CONFIG.FEDERATION_COMMUNITY_URL}/api/${CONFIG.FEDERATION_API}`,
|
||||
)
|
||||
}
|
||||
onShutdown(async (reason, details) => {
|
||||
onShutdown(async (reason, error) => {
|
||||
if (ShutdownReason.SIGINT === reason || ShutdownReason.SIGTERM === reason) {
|
||||
logger.info(`graceful shutdown: ${reason}`)
|
||||
} else {
|
||||
logger.error(`crash: ${reason} ${details}`)
|
||||
logger.error(`crash: ${reason}`, error)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
@ -12,18 +12,6 @@ export class BinaryData {
|
||||
private hex: string
|
||||
|
||||
constructor(input: Buffer | string | undefined) {
|
||||
if (!input) {
|
||||
logging.debug('constructor() with undefined input')
|
||||
}
|
||||
logging.debug(`constructor() input type: ${typeof input}`)
|
||||
logging.debug(`constructor() input isBuffer: ${Buffer.isBuffer(input)}`)
|
||||
if (typeof input === 'string') {
|
||||
logging.debug(`constructor() input: ${input}`)
|
||||
} else if (Buffer.isBuffer(input)) {
|
||||
logging.debug(`constructor() input: ${input.toString('hex')}`)
|
||||
} else {
|
||||
logging.debug(`constructor() unexpected input type: ${typeof input}`)
|
||||
}
|
||||
if (typeof input === 'string') {
|
||||
this.buf = Buffer.from(input, 'hex')
|
||||
this.hex = input
|
||||
@ -47,8 +35,10 @@ export class BinaryData {
|
||||
}
|
||||
|
||||
isSame(other: BinaryData): boolean {
|
||||
logging.debug(`isSame() this: ${this.buf}`)
|
||||
logging.debug(`isSame() other: ${other.buf}`)
|
||||
if (other === undefined || !(other instanceof BinaryData) || other.buf === undefined || !Buffer.isBuffer(other.buf)) {
|
||||
logging.error('other is invalid', other)
|
||||
return false
|
||||
}
|
||||
return this.buf.compare(other.buf) === 0
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,7 +10,7 @@ export enum ShutdownReason {
|
||||
* Setup graceful shutdown for the process
|
||||
* @param gracefulShutdown will be called if process is terminated
|
||||
*/
|
||||
export function onShutdown(shutdownHandler: (reason: ShutdownReason, details?: string) => Promise<void>) {
|
||||
export function onShutdown(shutdownHandler: (reason: ShutdownReason, error?: Error | any) => Promise<void>) {
|
||||
const signals: NodeJS.Signals[] = ['SIGINT', 'SIGTERM']
|
||||
signals.forEach(sig => {
|
||||
process.on(sig, async () => {
|
||||
@ -19,13 +19,13 @@ export function onShutdown(shutdownHandler: (reason: ShutdownReason, details?: s
|
||||
})
|
||||
})
|
||||
|
||||
process.on('uncaughtException', async (err, origin) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_EXCEPTION, `${origin}: ${err}`)
|
||||
process.on('uncaughtException', async (err) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_EXCEPTION, err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
process.on('unhandledRejection', async (reason, promise) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_REJECTION, `${promise}: ${reason}`)
|
||||
process.on('unhandledRejection', async (err) => {
|
||||
await shutdownHandler(ShutdownReason.UNCAUGHT_REJECTION, err)
|
||||
process.exit(1)
|
||||
})
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user