diff --git a/src/Illuminate/Http/Client/Response.php b/src/Illuminate/Http/Client/Response.php index f26886e2f80e..b73dd8706536 100644 --- a/src/Illuminate/Http/Client/Response.php +++ b/src/Illuminate/Http/Client/Response.php @@ -338,9 +338,8 @@ public function throwIfStatus($statusCode) */ public function throwUnlessStatus($statusCode) { - if (is_callable($statusCode) && - ! $statusCode($this->status(), $this)) { - return $this->throw(); + if (is_callable($statusCode)) { + return $statusCode($this->status(), $this) ? $this : $this->throw(); } return $this->status() === $statusCode ? $this : $this->throw(); diff --git a/tests/Http/HttpClientTest.php b/tests/Http/HttpClientTest.php index c2056867c970..6aadac7005ac 100644 --- a/tests/Http/HttpClientTest.php +++ b/tests/Http/HttpClientTest.php @@ -2194,6 +2194,16 @@ public function testRequestExceptionIsThrownUnlessStatusCodeIsSatisfied() } $this->assertNull($exception); + + $exception = null; + + try { + $this->factory->get('http://foo.com/api/500')->throwUnlessStatus(fn ($status) => $status === 500); + } catch (RequestException $e) { + $exception = $e; + } + + $this->assertNull($exception); } public function testRequestExceptionIsThrownIfIsClientError()