class Shift::Api::Core::Middleware::ErrorHandler

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

Attributes

app[RW]

Public Class Methods

new(app) click to toggle source
# File lib/shift/api/core/middleware/error_handler.rb, line 11
def initialize(app)
  self.app = app
end

Public Instance Methods

call(env) click to toggle source

Executes as normal but catches jsonapi client errors and translates them @param [Faraday::Env] env The environment from faraday

# 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