Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Response::getIsOk() to include entire 2xx range #240

Merged
merged 2 commits into from
Jul 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Yii Framework 2 HTTP client extension Change Log
2.0.16 under development
------------------------

- no changes in this release.
- Bug #240: Fixed `\yii\httpclient\Response::getIsOk()` to include entire 2xx response code range (rhertogh)


2.0.15 May 22, 2023
Expand Down
5 changes: 3 additions & 2 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ public function getStatusCode()
}

/**
* Checks if response status code is OK (status code = 20x)
* Checks if response status code is OK (status code = 2xx)
* @return bool whether response is OK.
* @throws Exception
*/
public function getIsOk()
{
return strncmp('20', $this->getStatusCode(), 2) === 0;
$statusCode = (int)$this->getStatusCode();
return $statusCode >= 200 && $statusCode < 300;
}

/**
Expand Down
2 changes: 2 additions & 0 deletions tests/ResponseTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ public function testUnableToGetStatusCode()
public function dataProviderIsOk()
{
return [
[100, false],
[200, true],
[201, true],
[226, true],
[400, false],
];
}
Expand Down
Loading