Class: TocDoc::Middleware::RaiseError Private
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- TocDoc::Middleware::RaiseError
- Defined in:
- lib/toc_doc/http/middleware/raise_error.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Faraday middleware that translates HTTP error responses and transport-level failures into typed Error subclasses, keeping Faraday as an internal implementation detail.
Placed as the outermost middleware so the retry middleware operates on raw Faraday exceptions and returns the final response after exhaustion.
Two-pronged error mapping:
- +on_complete+: inspects the HTTP status and raises the appropriate ResponseError subclass for 4xx/5xx responses.
- +rescue+ in +call+: catches Faraday transport errors and raises ConnectionError.
Constant Summary collapse
- STATUS_MAP =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Maps specific HTTP status codes to their typed error classes. Statuses not in this map fall back to ClientError (4xx) or ServerError (5xx).
{ 400 => TocDoc::BadRequest, 404 => TocDoc::NotFound, 422 => TocDoc::UnprocessableEntity, 429 => TocDoc::TooManyRequests }.freeze
Instance Method Summary collapse
-
#call(env) ⇒ Faraday::Response
private
Executes the request, raises ConnectionError on transport failures, and delegates HTTP error mapping to +on_complete+.
Instance Method Details
#call(env) ⇒ Faraday::Response
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Executes the request, raises ConnectionError on transport failures, and delegates HTTP error mapping to +on_complete+.
45 46 47 48 49 50 51 |
# File 'lib/toc_doc/http/middleware/raise_error.rb', line 45 def call(env) @app.call(env).on_complete do |response_env| on_complete(response_env) end rescue Faraday::TimeoutError, Faraday::ConnectionFailed, Faraday::SSLError => e raise TocDoc::ConnectionError, e. end |