Class: FaradayMiddleware::RaiseHttpException

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/faraday/raise_http_exception.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



6
7
8
9
# File 'lib/faraday/raise_http_exception.rb', line 6

def initialize(app)
  super app
  @parser = nil
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/faraday/raise_http_exception.rb', line 11

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
    when 400
      raise Bitmex::BadRequest, error_message_400(response)
    when 404
      raise Bitmex::NotFound, error_message_400(response)
    when 429
      raise Bitmex::TooManyRequests, error_message_400(response)
    when 500
      raise Bitmex::InternalServerError, error_message_500(response, "Something is technically wrong.")
    when 502
      raise Bitmex::BadGateway, error_message_500(response, "The server returned an invalid or incomplete response.")
    when 503
      raise Bitmex::ServiceUnavailable, error_message_500(response, "Bitmex is rate limiting your requests.")
    when 504
      raise Bitmex::GatewayTimeout, error_message_500(response, "504 Gateway Time-out")
    end
  end
end