Class: VistarClient::Middleware::ErrorHandler
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- VistarClient::Middleware::ErrorHandler
- Defined in:
- lib/vistar_client/middleware/error_handler.rb
Overview
Faraday response middleware that intercepts HTTP responses and raises appropriate VistarClient exceptions based on status codes.
This middleware handles:
-
401 Unauthorized -> AuthenticationError
-
4xx/5xx errors -> APIError (with status code and response body)
-
Network/connection failures -> ConnectionError
Constant Summary collapse
- CLIENT_ERROR_RANGE =
HTTP status codes that should raise exceptions
(400..499)
- SERVER_ERROR_RANGE =
HTTP status codes for server errors
(500..599)
Instance Method Summary collapse
-
#call(request_env) ⇒ Faraday::Response
Process the request and handle any errors.
Instance Method Details
#call(request_env) ⇒ Faraday::Response
Process the request and handle any errors
42 43 44 45 46 47 48 49 50 |
# File 'lib/vistar_client/middleware/error_handler.rb', line 42 def call(request_env) response = @app.call(request_env) check_for_errors(response) response rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e raise ConnectionError, "Connection failed: #{e.}" rescue Faraday::Error => e raise ConnectionError, "Network error: #{e.}" end |