Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// If additional properties are stored into Error object, like in InternalAvailability model:
// `throw createError(`Unfound asset type (ID ${asset.assetTypeId})`, { assetTypeId: asset.assetTypeId })`
// Without errorData, we lose `assetTypeId` information, because `apm.captureError()` won't store it
let errorData
if (error instanceof Error) {
const omittedErrorFields = [
'message',
'stack',
'statusCode',
'expose'
]
errorData = _.pick(error, _.difference(Object.keys(error), omittedErrorFields))
}
// passed context overrides default context properties
apm.captureError(error, {
user: removeUndefinedValues(newUser),
custom: removeUndefinedValues(Object.assign({ errorData }, newCustom)),
labels: removeUndefinedValues(newLabels),
message
})
}
}
}).then(lastLog => {
if (workflow.notifyUrl) {
return notifyAfterCompleted({
workflow,
lastLog,
event,
exposedEvent,
WorkflowLog,
runId,
platformId,
env
})
}
})
} catch (err) {
apm.captureError(err)
logError(err.response ? err.response.body : err, {
platformId,
env,
custom: {
workflowId: currentWorkflowId.id,
eventId: event.id,
runId
},
message: 'Fail to execute stelace workflow'
})
} finally {
if (apmSpans.allRuns) apmSpans.allRuns.end()
apmSpans = {} // clean for garbage collection
singleWorkflowTransaction.end()
}
export function internalServerErrorMiddleware(err: Error, req: any, res: express.Response, next: express.NextFunction) {
req.log.error(err);
apm.captureError(err);
if (err instanceof NotFoundError) {
return pageNotFoundMiddleware(req, res, next);
}
if (err instanceof UserFriendlyError) {
res.status(500);
res.send(internalServerError.render({
errorMessage: err.message,
location: platformLocation(process.env.AWS_REGION || /* istanbul ignore next */ ''),
}));
return;
}
res.status(500);
ctx.res.on('finish', () => {
apm.captureError(err);
debug('Sent error to APM server');
});
throw err;