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

SocketException distinction #379

Open
luzrain opened this issue Feb 24, 2025 · 2 comments
Open

SocketException distinction #379

luzrain opened this issue Feb 24, 2025 · 2 comments

Comments

@luzrain
Copy link

luzrain commented Feb 24, 2025

There is an Amp\Http\Client\SocketException exception that covers different types of connection errors. However, I found out that it's not possible to distinguish between them programmatically, they are all the same except for the error message.
I need to differentiate a specific error, and the only way to do that is to check if the error message contains a substring, which is not reliable.
What do you think we can do about this? My first thought is to add unique exception codes to all SocketException cases.

@iTearo
Copy link

iTearo commented Feb 25, 2025

I agree with the problem. In my case I get an exception with the text Receiving the response headers for ‘http://localhost:8080/’ failed, because the socket to ‘localhost:8080’ @ ‘???’ closed early with 0 bytes received within 10.001 seconds
My request has a timeout of 10 seconds $httpClient->request('GET', 'http://localhost:8080', ['timeout' => 10, 'http_errors' => true]) , but the exception I encounter is SocketException instead of the expected TimeoutException.

PS: I use amphp/http-client-guzzle-adapter.

@iTearo
Copy link

iTearo commented Feb 25, 2025

Moreover, there is an old issue telling us that it is exactly the timeout error, thus it may be distincted to TimeoutException #286 (comment)

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

No branches or pull requests

2 participants