fix(JobExecutor#exec): correctly log the error
This commit is contained in:
@@ -12,6 +12,7 @@ import { BaseError } from 'make-error'
|
||||
import { crossProduct } from './math'
|
||||
import {
|
||||
forEach,
|
||||
serializeError,
|
||||
thunkToArray
|
||||
} from './utils'
|
||||
|
||||
@@ -117,11 +118,11 @@ export default class JobExecutor {
|
||||
event: 'job.end',
|
||||
runJobId
|
||||
})
|
||||
} catch (e) {
|
||||
} catch (error) {
|
||||
this._logger.error(`The execution of ${job.id} has failed.`, {
|
||||
event: 'job.end',
|
||||
runJobId,
|
||||
error: e
|
||||
error: serializeError(error)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -484,6 +484,15 @@ export const scheduleFn = (cronTime, fn, timeZone) => {
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Create a serializable object from an error.
|
||||
export const serializeError = error => ({
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
...error // Copy enumerable properties.
|
||||
})
|
||||
|
||||
// -------------------------------------------------------------------
|
||||
|
||||
// Create an array which contains the results of one thunk function.
|
||||
// Only works with synchronous thunks.
|
||||
export const thunkToArray = thunk => {
|
||||
|
||||
@@ -15,7 +15,8 @@ import {
|
||||
createRawObject,
|
||||
forEach,
|
||||
isFunction,
|
||||
noop
|
||||
noop,
|
||||
serializeError
|
||||
} from '../utils'
|
||||
|
||||
// ===================================================================
|
||||
@@ -258,11 +259,7 @@ export default class Api {
|
||||
method: name,
|
||||
params,
|
||||
duration: Date.now() - startTime,
|
||||
error: {
|
||||
message: error.message,
|
||||
stack: error.stack,
|
||||
...error // Copy enumerable properties.
|
||||
}
|
||||
error: serializeError(error)
|
||||
}
|
||||
const message = `${userName} | ${name}(${JSON.stringify(params)}) [${ms(Date.now() - startTime)}] =!> ${error}`
|
||||
|
||||
|
||||
Reference in New Issue
Block a user