class Stream::RaiseHttpException

Public Class Methods

new(app) click to toggle source
Calls superclass method
# File lib/stream/client.rb, line 217
def initialize(app)
  super app
  @parser = nil
end

Public Instance Methods

call(env) click to toggle source
# File lib/stream/client.rb, line 200
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

Private Instance Methods

_build_error_message(response) click to toggle source
# File lib/stream/client.rb, line 224
def _build_error_message(response)
  response = JSON.parse(response)
  msg = "#{response['exception']} details: #{response['detail']}"
  if response.key?('exception_fields')
    response['exception_fields'].map do |field, messages|
      msg << "\n#{field}: #{messages}"
    end
  end
  msg
end
error_message(response, body = nil) click to toggle source
# File lib/stream/client.rb, line 235
def error_message(response, body = nil)
  "#{response[:method].to_s.upcase} #{response[:url]}: #{["#{response[:status]}:", body].compact.join(' ')}"
end