Class: PurpleAirApi::V1::RaiseHttpException
- Inherits:
-
Faraday::Middleware
- Object
- Faraday::Middleware
- PurpleAirApi::V1::RaiseHttpException
- Defined in:
- lib/purple_air_api/V1/raise_http_exception.rb
Overview
Handles any HTTP exceptions for 400 and 500 error codes
Instance Method Summary collapse
-
#call(env) ⇒ Object
A switch statement which determines which error to raise depending on error code.
-
#initialize(app) ⇒ RaiseHttpException
constructor
Faraday syntax for implementing middleware.
Constructor Details
#initialize(app) ⇒ RaiseHttpException
Faraday syntax for implementing middleware
27 28 29 30 |
# File 'lib/purple_air_api/V1/raise_http_exception.rb', line 27 def initialize(app) super app @parser = nil end |
Instance Method Details
#call(env) ⇒ Object
A switch statement which determines which error to raise depending on error code
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/purple_air_api/V1/raise_http_exception.rb', line 8 def call(env) @app.call(env).on_complete do |response| self.response = response case response[:status].to_i when 400 raise ApiError.new(, parsed_response[:error], response) when 403 raise ApiKeyError.new(, parsed_response[:error], response) when 404 raise NotFoundError.new(, parsed_response[:error], response) when 415 raise MissingJsonPayloadError.new(, 'MissingJsonPayloadError', response) when 500 raise ServerError.new(, 'ServerError', response) end end end |