(exchange: CopilotRequestExchange)
| 353 | } |
| 354 | |
| 355 | async function run(exchange: CopilotRequestExchange): Promise<void> { |
| 356 | try { |
| 357 | await handler[kHandle](exchange); |
| 358 | if (!exchange.finished) { |
| 359 | await finalize( |
| 360 | exchange, |
| 361 | 502, |
| 362 | "Copilot request handler returned without finalising the response (call responseBody.end() or .error())." |
| 363 | ); |
| 364 | } |
| 365 | } catch (err) { |
| 366 | if (exchange.cancelled || exchange.signal.aborted) { |
| 367 | // The runtime already cancelled this request; the handler's |
| 368 | // throw is just the abort propagating out of its upstream call. |
| 369 | await finalize(exchange, 499, "Request cancelled by runtime", "cancelled"); |
| 370 | return; |
| 371 | } |
| 372 | const message = err instanceof Error ? err.message : String(err); |
| 373 | await finalize(exchange, 502, message); |
| 374 | } finally { |
| 375 | pending.delete(exchange.requestId); |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | return { |
| 380 | async httpRequestStart( |
no test coverage detected