Skip to content

Commit

Permalink
model statusCode
Browse files Browse the repository at this point in the history
  • Loading branch information
BBB committed Nov 5, 2023
1 parent f226a33 commit 72d719c
Show file tree
Hide file tree
Showing 5 changed files with 443 additions and 94 deletions.
96 changes: 6 additions & 90 deletions packages/http-client/src/ImmutableResponse.ts
Original file line number Diff line number Diff line change
@@ -1,95 +1,9 @@
import { IncomingHttpResponse } from "@ollierelph/sensible-fetch";
import { ImmutableHeaders } from "~/src/ImmutableHeaders";
import { ImmutableURL } from "~/src/ImmutableURL";
import { StatusCode } from "~/src/StatusCode";

type StatusCode =
| 100
| 101
| 102
| 103
| 200
| 201
| 202
| 203
| 204
| 205
| 206
| 207
| 208
| 218
| 226
| 300
| 301
| 302
| 303
| 304
| 306
| 307
| 308
| 400
| 401
| 402
| 403
| 404
| 405
| 406
| 407
| 408
| 409
| 410
| 411
| 412
| 413
| 414
| 415
| 416
| 417
| 418
| 419
| 420
| 421
| 422
| 423
| 424
| 426
| 428
| 429
| 431
| 440
| 444
| 449
| 450
| 451
| 494
| 495
| 496
| 497
| 498
| 499
| 500
| 501
| 502
| 503
| 504
| 505
| 506
| 507
| 508
| 509
| 510
| 511
| 520
| 521
| 522
| 523
| 524
| 525
| 526
| 527
| 530
| 598;

export class ImmutableResponse<Status extends StatusCode>
export class ImmutableResponse<Status extends StatusCode<any>>
implements Readonly<IncomingHttpResponse<ImmutableURL, Status>>
{
#response: IncomingHttpResponse;
Expand All @@ -99,8 +13,10 @@ export class ImmutableResponse<Status extends StatusCode>
this.#response = response;
}

fromResponse(response: IncomingHttpResponse) {
return new ImmutableResponse(response.status as StatusCode, response);
static fromResponse<Response extends IncomingHttpResponse>(
response: Response,
) {
return new ImmutableResponse(StatusCode.from(response.status), response);
}

get status() {
Expand Down

0 comments on commit 72d719c

Please sign in to comment.