Skip to content

Commit

Permalink
Addressed all comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Iswarya Sankaran committed May 18, 2022
1 parent b8572e7 commit 5344340
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 4 deletions.
9 changes: 9 additions & 0 deletions documentation/3-streams.md
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,15 @@ The server's IP address.
Whether the response comes from cache or not.
### `ok`
**Type: `boolean`**
**Note:**
> - This property need not be checked if throwHttpErrors is true.
Whether the response was successful (status code in the range 200-299).
### `statusCode`
**Type: `number`**
Expand Down
2 changes: 1 addition & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ export default class Request extends Duplex implements RequestEvents<Request> {
typedResponse.isFromCache = (this._nativeResponse as any).fromCache ?? false;
typedResponse.ip = this.ip;
typedResponse.retryCount = this.retryCount;
typedResponse.ok = (statusCode >= 200 && statusCode <= 299);
typedResponse.ok = isResponseOk(typedResponse);

this._isFromCache = typedResponse.isFromCache;

Expand Down
5 changes: 3 additions & 2 deletions source/core/response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ export interface PlainResponse extends IncomingMessageWithTimings {
body?: unknown;

/**
Whether the response status code is 2xx.
Whether the response was successful (status code in the range 200-299).
This property need not be checked if throwHttpErrors is true.
*/
ok?: boolean;
ok: boolean;
}

// For Promise support
Expand Down
2 changes: 1 addition & 1 deletion test/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,7 @@ test('status code 200 has response ok is true', withServer, async (t, server, go
const promise = got('');
await t.notThrowsAsync(promise);
const {statusCode, body, ok} = await promise;
t.is(ok, true);
t.true(ok);
t.is(statusCode, 200);
t.is(body, '');
});
Expand Down

0 comments on commit 5344340

Please sign in to comment.