Class: Force::Middleware::RaiseError

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

Instance Method Summary collapse

Instance Method Details

#bodyObject



21
22
23
# File 'lib/force/middleware/raise_error.rb', line 21

def body
  JSON.parse(@env[:body])
end

#messageObject



17
18
19
# File 'lib/force/middleware/raise_error.rb', line 17

def message
  "#{body.first['errorCode']}: #{body.first['message']}"
end

#on_complete(env) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/force/middleware/raise_error.rb', line 3

def on_complete(env)
  @env = env
  case env[:status]
  when 404
    raise Faraday::Error::ResourceNotFound, message
  when 401
    raise Force::UnauthorizedError, message
  when 413
    raise Faraday::Error::ClientError.new("HTTP 413 - Request Entity Too Large", env[:response])
  when 400...600
    raise Faraday::Error::ClientError.new(message, env[:response])
  end
end