| 85 | } |
| 86 | |
| 87 | function captureReply(rep: FastifyReply) { |
| 88 | const savedReply = { |
| 89 | // @ts-expect-error Exists |
| 90 | id: rep.__id, |
| 91 | headers: rep.getHeaders(), |
| 92 | timestamp: Date.now(), |
| 93 | // @ts-expect-error Exists |
| 94 | payload: rep.__payload, |
| 95 | statusCode: rep.statusCode |
| 96 | }; |
| 97 | |
| 98 | if (RESPONSE_BUFFER.length > 10) { |
| 99 | appendFileSync( |
| 100 | join(LOGS_DIRECTORY, RESPONSE_CAPTURE_FILE), |
| 101 | RESPONSE_BUFFER.map(rb => JSON.stringify(rb)).join('\n') + '\n' |
| 102 | ); |
| 103 | RESPONSE_BUFFER = [savedReply]; |
| 104 | } else { |
| 105 | RESPONSE_BUFFER.push(savedReply); |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Returns a subset of the given object with the values or properties given removed. |