Class: InstagramBasicDisplayAPI::RaiseHttpException

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException

Returns a new instance of RaiseHttpException.



30
31
32
33
# File 'lib/instagram_basic_display_api/raise_http_exception.rb', line 30

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

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/instagram_basic_display_api/raise_http_exception.rb', line 7

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