Class: Sendle::Api::Factories::Errors

Inherits:
Object
  • Object
show all
Defined in:
lib/sendle/api/factories/errors.rb

Class Method Summary collapse

Class Method Details

.new_error(rest_client_error) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/sendle/api/factories/errors.rb', line 6

def self.new_error(rest_client_error)
  response = JSON.parse(rest_client_error.response)
  error_text = response['error_description']
  messages = response['messages']

  case rest_client_error
  when RestClient::Unauthorized
    Sendle::Api::Errors::Unauthorized.new(error_text)
  when RestClient::PaymentRequired
    Sendle::Api::Errors::PaymentRequired.new(error_text)
  when RestClient::UnprocessableEntity
    Sendle::Api::Errors::UnprocessableEntity.new(messages)
  when  RestClient::PreconditionFailed
    Sendle::Api::Errors::PreconditionFailed.new(error_text)
  end
end