(res, options)
| 29 | } |
| 30 | |
| 31 | async function sendFailure (res, options) { |
| 32 | const { error, headers, onSendFailureDuringShutdown, exposeStackTraces, statusCode, statusResponse, statusError, statusErrorResponse } = options |
| 33 | |
| 34 | function replaceErrors (_, value) { |
| 35 | if (value instanceof Error) { |
| 36 | const error = {} |
| 37 | |
| 38 | Object.getOwnPropertyNames(value).forEach(function (key) { |
| 39 | if (exposeStackTraces !== true && key === 'stack') return |
| 40 | error[key] = value[key] |
| 41 | }) |
| 42 | |
| 43 | return error |
| 44 | } |
| 45 | |
| 46 | return value |
| 47 | } |
| 48 | |
| 49 | if (onSendFailureDuringShutdown) { |
| 50 | await onSendFailureDuringShutdown() |
| 51 | } |
| 52 | res.statusCode = statusCode || statusError |
| 53 | const responseBody = statusResponse || statusErrorResponse |
| 54 | res.setHeader('Content-Type', 'application/json') |
| 55 | res.writeHead(statusCode || statusError, headers) |
| 56 | if (error) { |
| 57 | return res.end(JSON.stringify( |
| 58 | Object.assign( |
| 59 | responseBody, { |
| 60 | error, |
| 61 | details: error |
| 62 | }), replaceErrors)) |
| 63 | } |
| 64 | res.end(statusResponse ? JSON.stringify(responseBody) : FAILURE_RESPONSE) |
| 65 | } |
| 66 | |
| 67 | const intialState = { |
| 68 | isShuttingDown: false |
no outgoing calls
no test coverage detected
searching dependent graphs…