Class: FmRest::Cloud::AuthErrorHandler
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- FmRest::Cloud::AuthErrorHandler
- Defined in:
- lib/fmrest/cloud/auth_error_handler.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app, settings) ⇒ AuthErrorHandler
constructor
A new instance of AuthErrorHandler.
Constructor Details
#initialize(app, settings) ⇒ AuthErrorHandler
Returns a new instance of AuthErrorHandler.
6 7 8 9 |
# File 'lib/fmrest/cloud/auth_error_handler.rb', line 6 def initialize(app, settings) super(app) @settings = settings end |
Instance Method Details
#call(env) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/fmrest/cloud/auth_error_handler.rb', line 11 def call(env) request_body = env[:body] # After failure env[:body] is set to the response body @app.call(env) rescue APIError::AccountError => e ClarisIdTokenManager.new(@settings).expire_token # Faraday::Request::Authorization will not get a new token if the # Authorization header is already set env.request_headers.delete("Authorization") env[:body] = request_body @app.call(env) end |