Class: Gitlab::Faraday::ErrorCallback
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Gitlab::Faraday::ErrorCallback
- Defined in:
- lib/gitlab/faraday/error_callback.rb
Overview
Simple Faraday Middleware that catches any error risen during the request and run the configured callback. (lostisland.github.io/faraday/middleware/)
By default, a no op callback is setup.
Note that the error is not swallowed: it will be rerisen again. In that regard, this callback acts more like an error spy than anything else.
The callback has access to the request env and the exception instance. For more details, see lostisland.github.io/faraday/middleware/custom
Faraday.new do |conn|
conn.request(
:error_callback,
callback: -> (env, exception) { Rails.logger.debug("Error #{exception.class.name} when trying to contact #{env[:url]}" ) }
)
conn.adapter(:net_http)
end
Defined Under Namespace
Classes: Options
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, options = nil) ⇒ ErrorCallback
constructor
A new instance of ErrorCallback.
Constructor Details
#initialize(app, options = nil) ⇒ ErrorCallback
Returns a new instance of ErrorCallback.
24 25 26 27 |
# File 'lib/gitlab/faraday/error_callback.rb', line 24 def initialize(app, = nil) super(app) = ::Gitlab::Faraday::ErrorCallback::Options.from() # rubocop: disable CodeReuse/ActiveRecord end |
Instance Method Details
#call(env) ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/gitlab/faraday/error_callback.rb', line 29 def call(env) @app.call(env) rescue StandardError => e .callback&.call(env, e) raise end |