lostisland / faraday

Simple, but flexible HTTP client library, with support for multiple backends.

Home Page:https://lostisland.github.io/faraday

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing HTTP 408 Request Timeout specific Faraday ClientError?

tisba opened this issue · comments

Hey there. I noticed that there is no specific Faraday::ClientError for HTTP 408:

# Raised by Faraday::Response::RaiseError in case of a 400 response.
class BadRequestError < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 401 response.
class UnauthorizedError < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 403 response.
class ForbiddenError < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 404 response.
class ResourceNotFound < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 407 response.
class ProxyAuthError < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 409 response.
class ConflictError < ClientError
end
# Raised by Faraday::Response::RaiseError in case of a 422 response.
class UnprocessableEntityError < ClientError
end
does not contain an error for HTTP 408 Request Timeout. We recently seen this one a couple of times when talking to the Slack API for example.

Is there a reason this is not defined? If not, would you accept a PR to add this?

commented

Hi @tisba 👋, no real reason for it to be missing, we simply add specific classes only for common errors.
There's no downside to adding a new class that inherits from ClientError, so a PR that does that would be welcome.

Out of curiosity, are you experiencing this error under some special circumstances? I checked the RFC and it says that the error is normally sent on an "idle connection". That sounds like something hard to achieve with Ruby unless you're doing parallel/concurrent requests?

We're using the net_http_persistent adapter. Maybe that's because of this. We don't see it often, it would just be easier for us to handle with an exception and it would help to keep the code clean.

According to https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/408:

[…]It is sent on an idle connection by some servers, even without any previous request by the client.

Which I found quite interesting, especially pre HTTP/2. I've been doing web stuff for a long time by now and lot's of performance testing… I've never seen HTTP 408 before 🤷

commented

Which I found quite interesting, especially pre HTTP/2.
That's exactly my thought and why I was curious to ask. If the connection is "idle" that would mean the ruby program is doing something else, meaning that it's probably not even listening to the connection.

The only way this could happen is if there was some sort of async listener (e.g. in a separate thread/fiber) or MAYBE, the way this works is that next time you fire a request on that connection, the adapter receives the 408 response that came earlier on?

Anyways, this is just curiosity 😄 it doesn't really stops adding the next error