| 373 | } |
| 374 | |
| 375 | class ClientResponseImpl extends IncomingMessageImpl<HttpClientError.HttpClientError> |
| 376 | implements HttpClientResponse.HttpClientResponse, Pipeable |
| 377 | { |
| 378 | readonly [HttpClientResponse.TypeId]: typeof HttpClientResponse.TypeId |
| 379 | readonly request: HttpClientRequest.HttpClientRequest |
| 380 | |
| 381 | constructor( |
| 382 | request: HttpClientRequest.HttpClientRequest, |
| 383 | source: globalThis.XMLHttpRequest |
| 384 | ) { |
| 385 | super(source, (cause) => |
| 386 | new HttpClientError.HttpClientError({ |
| 387 | reason: new HttpClientError.DecodeError({ |
| 388 | request, |
| 389 | response: this, |
| 390 | cause |
| 391 | }) |
| 392 | })) |
| 393 | this.request = request |
| 394 | this[HttpClientResponse.TypeId] = HttpClientResponse.TypeId |
| 395 | } |
| 396 | |
| 397 | get status() { |
| 398 | return this.source.status |
| 399 | } |
| 400 | |
| 401 | get formData(): Effect.Effect<FormData, HttpClientError.HttpClientError> { |
| 402 | return Effect.flatMap(this.arrayBuffer, (body) => |
| 403 | Effect.tryPromise({ |
| 404 | try: () => new globalThis.Response(body, { headers: this.headers }).formData(), |
| 405 | catch: this.onError |
| 406 | })) |
| 407 | } |
| 408 | |
| 409 | override toString(): string { |
| 410 | return `ClientResponse(${this.status})` |
| 411 | } |
| 412 | |
| 413 | toJSON(): unknown { |
| 414 | return HttpIncomingMessage.inspect(this, { |
| 415 | _id: "@effect/platform/HttpClientResponse", |
| 416 | request: this.request.toJSON(), |
| 417 | status: this.status |
| 418 | }) |
| 419 | } |
| 420 | |
| 421 | pipe() { |
| 422 | return pipeArguments(this, arguments) |
| 423 | } |
| 424 | } |
| 425 | |
| 426 | /** |
| 427 | * Layer that provides an `HttpClient` implementation backed by the browser `XMLHttpRequest` API. |
nothing calls this directly
no outgoing calls
no test coverage detected