Class: Faraday::ColrapiErrors::Middleware

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

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Middleware

Returns a new instance of Middleware.



30
31
32
33
# File 'lib/bananomia/faraday.rb', line 30

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
# File 'lib/bananomia/faraday.rb', line 11

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