Class: SmartlingApi::Errors::RaiseError

Inherits:
Faraday::Response::Middleware
  • Object
show all
Defined in:
lib/smartling_api/errors/raise_error.rb

Overview

Middleware for Faraday error handling

Constant Summary collapse

ERRORS =

Mapping of Smartling Error response

{
  404 => NotFound,
  422 => UnprocessableEntity,
  500 => InternalServer
}

Instance Method Summary collapse

Instance Method Details

#on_complete(response) ⇒ nil

Hook for faraday middleware to respond to errors. Will raise mapped error, but will default to using Errors::Client.

Raises:

  • (Errors::Client)

    Specific error raised depending on response status code.



25
26
27
28
29
# File 'lib/smartling_api/errors/raise_error.rb', line 25

def on_complete(response)
  return if response.status < 400

  raise ERRORS.fetch(response.status, Client), get_message(response)
end