Class: Stream::RaiseHttpException

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/stream/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RaiseHttpException



184
185
186
187
# File 'lib/stream/client.rb', line 184

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

Instance Method Details

#call(env) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
# File 'lib/stream/client.rb', line 167

def call(env)
  @app.call(env).on_complete do |response|
    case response[:status].to_i
      when 200..203
        return response
      when 401
        raise StreamApiResponseException, error_message(response, 'Bad feed')
      when 403
        raise StreamApiResponseException, error_message(response, 'Bad auth/headers')
      when 404
        raise StreamApiResponseException, error_message(response, 'url not found')
      when 204...600
        raise StreamApiResponseException, error_message(response, _build_error_message(response.body))
    end
  end
end