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

Convert SocketException to guzzle ConnectException #3

Open
wants to merge 1 commit into
base: 1.x
Choose a base branch
from

Conversation

luzrain
Copy link

@luzrain luzrain commented Feb 24, 2025

Convert Amp\Http\Client\SocketException to guzzle GuzzleHttp\Exception\ConnectException

Comment on lines +143 to +144
} catch (SocketException $e) {
$promise->reject(new ConnectException($e->getMessage(), $request, $e));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this is not always right, e.g. if a socket is closed while the request is sent, we likely don't want a ConnectException?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, it might be better to handle this the same way as in CurlFactory.php, where only certain types of errors are converted to ConnectException, while all others are converted to RequestException.
But all raw SocketException should definitely be converted to either ConnectException or RequestException to be compatible with Guzzle, which always throws its own internal exceptions in such cases. Applications rely on these Guzzle exceptions, and they must remain consistent no matter what handler is used under the hood.

The only problem is that we cannot differentiate between SocketException cases. We need to add some form of differentiation to implement this properly.
See my related issue about this: amphp/http-client#379

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

Successfully merging this pull request may close these issues.

2 participants