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

[11.x] Include ConnectionException in ConnectionFailed events #52069

Merged
merged 7 commits into from
Jul 10, 2024

Conversation

alexbowers
Copy link
Contributor

@alexbowers alexbowers commented Jul 9, 2024

Currently, you receive an event (\Illuminate\Http\Client\Events\ConnectionFailed) if a HTTP Request has hit a timeout of some kind (or some other error), however, the event only has access to the request, which doesn't include any information about the nature of the failure. There is no response that has been received, but we do have an exception (\Illuminate\Http\Client\ConnectionException) that is now being passed.

Copy link

github-actions bot commented Jul 9, 2024

Thanks for submitting a PR!

Note that draft PR's are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@alexbowers alexbowers changed the title Update PendingRequest.php [11.x] Include ConnectionException in ConnectionFailed events Jul 9, 2024
@alexbowers alexbowers marked this pull request as ready for review July 9, 2024 15:29
@taylorotwell taylorotwell merged commit 0be8438 into laravel:11.x Jul 10, 2024
27 of 28 checks passed
@mabdullahsari
Copy link
Contributor

This was a breaking change for us...

@mabdullahsari
Copy link
Contributor

We have old HTTP clients from the pre-HttpFactory era for which we've written stop-gap Guzzle middleware to dispatch Illuminate events to make them appear on Telescope. Can you please revert this? @driesvints

@mabdullahsari
Copy link
Contributor

Case in point:

class HttpClientEventsMiddleware
{
    public static function make(): self
    {
        return app(self::class);
    }

    public function __construct(private readonly Dispatcher $dispatcher) {}

    public function __invoke(callable $handler)
    {
        return function ($request, array $options) use ($handler) {
            $this->dispatcher->dispatch(new RequestSending($illuminateRequest = new Request($request)));

            return $handler($request, $options)->then(
                $this->onSuccess($illuminateRequest),
                $this->onFailure($illuminateRequest)
            );
        };
    }

    protected function onSuccess(Request $request)
    {
        return function ($response) use ($request) {
            $this->dispatcher->dispatch(new ResponseReceived($request, new Response($response)));

            return $response;
        };
    }

    protected function onFailure(Request $request)
    {
        return function ($reason) use ($request) {
            $this->dispatcher->dispatch(new ConnectionFailed($request));

            return Create::rejectionFor($reason);
        };
    }
}

@alexbowers
Copy link
Contributor Author

Ah sorry, I didn't realise this would be a feature that people are initiating themselves.

Happy for this to be reverted, and for the original PR to be focused against the next major version so that the BC can be documented properly

@mabdullahsari
Copy link
Contributor

Ah sorry, I didn't realise this would be a feature that people are initiating themselves.

Happy for this to be reverted, and for the original PR to be focused against the next major version so that the BC can be documented properly

I'm sorry for this unexpected pushback, but we can't allocate resources to upgrade these old HTTP clients at this time. Thank you so much for your understanding!

@alexbowers
Copy link
Contributor Author

alexbowers commented Jul 18, 2024 via email

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

Successfully merging this pull request may close these issues.

3 participants