( nodeResponse: Http.ServerResponse, originalResponse: HttpServerResponse )
| 1299 | } |
| 1300 | |
| 1301 | const handleCause = ( |
| 1302 | nodeResponse: Http.ServerResponse, |
| 1303 | originalResponse: HttpServerResponse |
| 1304 | ) => |
| 1305 | <E>(originalCause: Cause.Cause<E>) => |
| 1306 | Effect.flatMap(causeResponse(originalCause), ([response, cause]) => { |
| 1307 | const headersSent = nodeResponse.headersSent |
| 1308 | let abort = headersSent |
| 1309 | if (!headersSent) { |
| 1310 | if (!isFinalStatus(response.status)) { |
| 1311 | cause = Cause.combine(cause, Cause.die(invalidStatusError(response.status))) |
| 1312 | response = internalServerError |
| 1313 | } |
| 1314 | try { |
| 1315 | writeHead(nodeResponse, response, {}) |
| 1316 | } catch { |
| 1317 | // HTTP/2 keeps the headers of a rejected `writeHead`, so the fallback can throw too |
| 1318 | abort = true |
| 1319 | } |
| 1320 | } |
| 1321 | if (!nodeResponse.writableEnded) { |
| 1322 | // Ending a started response normally would make a partial body look complete |
| 1323 | if (abort) { |
| 1324 | // An error resets an HTTP/2 stream with INTERNAL_ERROR rather than NO_ERROR. On |
| 1325 | // HTTP/1.1 it could reach `clientError` listeners, and the socket closes either way. |
| 1326 | nodeResponse.destroy(isHttp2(nodeResponse.req) ? new Error("The response was aborted") : undefined) |
| 1327 | } else { |
| 1328 | nodeResponse.end() |
| 1329 | } |
| 1330 | } |
| 1331 | return Effect.failCause( |
| 1332 | headersSent |
| 1333 | ? Cause.combine(originalCause, Cause.die(originalResponse)) |
| 1334 | : cause |
| 1335 | ) |
| 1336 | }) |
no test coverage detected