Class: Shift::Api::Core::Middleware::ErrorHandler
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- Shift::Api::Core::Middleware::ErrorHandler
- Defined in:
- lib/shift/api/core/middleware/error_handler.rb
Overview
Middleware to translate json api client errors to Shift::Api::Core errors
This is so as to not expose json api client stuff to the outside world
Instance Method Summary collapse
-
#call(env) ⇒ Object
Executes as normal but catches jsonapi client errors and translates them.
-
#initialize(app) ⇒ ErrorHandler
constructor
A new instance of ErrorHandler.
Constructor Details
#initialize(app) ⇒ ErrorHandler
Returns a new instance of ErrorHandler.
11 12 13 |
# File 'lib/shift/api/core/middleware/error_handler.rb', line 11 def initialize(app) self.app = app end |
Instance Method Details
#call(env) ⇒ Object
Executes as normal but catches jsonapi client errors and translates them
17 18 19 20 21 |
# File 'lib/shift/api/core/middleware/error_handler.rb', line 17 def call(env) app.call(env) rescue JsonApiClient::Errors::ApiError => ex raise ex.class.name.gsub(/^JsonApiClient::/, "Shift::Api::Core::").constantize.from_jsonapi_client(ex) end |