MCPcopy
hub / github.com/godaddy/terminus / sendFailure

Function sendFailure

lib/terminus.js:31–65  ·  view source on GitHub ↗
(res, options)

Source from the content-addressed store, hash-verified

29}
30
31async 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
67const intialState = {
68 isShuttingDown: false

Callers 1

createHandlerFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…