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

HTTP client automatically throws exception after retrying #40055

Closed
mattkingshott opened this issue Dec 15, 2021 · 2 comments
Closed

HTTP client automatically throws exception after retrying #40055

mattkingshott opened this issue Dec 15, 2021 · 2 comments

Comments

@mattkingshott
Copy link
Contributor

  • Laravel Version: 8.75.0
  • PHP Version: 8.1.0
  • Database Driver & Version: MySQL 8.0.27

Description:

When a retry is specified within the HTTP client, and the retry limit is reached, then the response is automatically thrown. Since there is no way to hook into the throw method, you'll always get a RequestException. Therefore, you cannot do things like $response->failed()

The problem lies within Illuminate\Http\Client\PendingRequest, on lines 682-684:

if ($this->tries > 1 && ! $response->successful()) {
    $response->throw();
}

Steps To Reproduce:

Simply, add a retry configuration to the HTTP client:

Http::fake([
    '*' => Http::response(['error'], 403),
]);

$response = Http::retry(3, 5000)->post('https://example.com/route'); 

// The above line throws a RequestException, so the below error handling will not be reached

if ($response->failed()) {
    // error handling
}
@driesvints
Copy link
Member

Hey @mattkingshott, this is the expected behaviour. Please see the docs here:

Screenshot 2021-12-16 at 14 28 39

If you want to see a different behaviour then please attempt a PR. Thanks

@mattkingshott
Copy link
Contributor Author

Oh my. Sorry I missed that. Maybe will attempt a PR for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants