Class: SemaphoreClient::HttpClient::ResponseErrorMiddleware

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/semaphore_client/http_client.rb

Instance Method Summary collapse

Instance Method Details

#call(env) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/semaphore_client/http_client.rb', line 6

def call(env)
  @app.call(env).on_complete do |env|
    case env[:status]
    when 401
      raise SemaphoreClient::Exceptions::Unauthorized, env
    when 404
      raise SemaphoreClient::Exceptions::NotFound, env
    when 405
      raise SemaphoreClient::Exceptions::NotAllowed, env
    when 409
      raise SemaphoreClient::Exceptions::Conflict, env
    when 422
      raise SemaphoreClient::Exceptions::UnprocessableEntity, env
    when 400...500
      raise SemaphoreClient::Exceptions::BadRequest, env
    when 500...600
      raise SemaphoreClient::Exceptions::ServerError, env
    end
  end
end