Class: Croudia::Response::RaiseError

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

Instance Method Summary collapse

Instance Method Details

#on_complete(env) ⇒ Object

Raises:

  • (error_class)


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/croudia/response/raise_error.rb', line 7

def on_complete(env)
  error_class = case env[:status]
  when 400
    Croudia::Error::BadRequest
  when 401
    Croudia::Error::Unauthorized
  when 403
    Croudia::Error::Forbidden
  when 404
    Croudia::Error::NotFound
  when 400 .. 499
    Croudia::Error::ClientError
  when 500
    Croudia::Error::InternalServerError
  when 502
    Croudia::Error::BadGateway
  when 503
    Croudia::Error::Unavailable
  when 500 .. 599
    Croudia::Error::ServerError
  else
    return
  end

  raise error_class.new(env)
end