Class: Faraday::EdsExceptionMiddleware
- Inherits:
-
Middleware
- Object
- Middleware
- Faraday::EdsExceptionMiddleware
- Defined in:
- lib/faraday/eds_exception_middleware.rb
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ EdsExceptionMiddleware
constructor
A new instance of EdsExceptionMiddleware.
Constructor Details
#initialize(app) ⇒ EdsExceptionMiddleware
Returns a new instance of EdsExceptionMiddleware.
7 8 9 |
# File 'lib/faraday/eds_exception_middleware.rb', line 7 def initialize(app) super app 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 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/faraday/eds_exception_middleware.rb', line 11 def call(env) begin @app.call(env).on_complete do |response| case response.status when 200 when 400 if response.body['ErrorNumber'] == '132' raise EBSCO::EDS::NotFound.new((response)) else raise EBSCO::EDS::BadRequest.new((response)) end # when 401 # raise EBSCO::EDS::Unauthorized.new # when 403 # raise EBSCO::EDS::Forbidden.new # when 404 # raise EBSCO::EDS::NotFound.new # when 429 # raise EBSCO::EDS::TooManyRequests.new when 500 raise EBSCO::EDS::InternalServerError.new when 503 raise EBSCO::EDS::ServiceUnavailable.new else raise EBSCO::EDS::BadRequest.new((response)) end end rescue Faraday::ConnectionFailed raise EBSCO::EDS::ConnectionFailed.new end end |