Skip to content

Commit

Permalink
🐛 FIX: Keep statusCode on HttpClientResponse for compatibility (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed Aug 24, 2022
1 parent cd7657e commit d1b89c8
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/HttpClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ export class HttpClient extends EventEmitter {
opaque,
data,
status: res.status,
statusCode: res.status,
headers: res.headers,
url: lastUrl,
redirected: res.requestUrls.length > 1,
Expand Down
2 changes: 2 additions & 0 deletions src/Response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export type HttpClientResponse = {
opaque: unknown;
data: any
status: number;
// alias to status, keep compatibility
statusCode: number;
headers: IncomingHttpHeaders;
url: string;
redirected: boolean;
Expand Down
1 change: 1 addition & 0 deletions test/options.followRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ describe('options.followRedirect.test.js', () => {
followRedirect: true,
});
assert.equal(response.res.statusCode, 200);
assert.equal(response.statusCode, response.res.statusCode);
assert((response.data as Buffer).length > 100);
assert.equal(response.url, `${_url}redirect-to-url`);
assert.equal(response.requestUrls.length, 2);
Expand Down

0 comments on commit d1b89c8

Please sign in to comment.