lib/scalyr/common/client.rb
# Process responses from Scalyr, raising appropriate exceptions if needed
Process responses from Scalyr, raising appropriate exceptions if needed
Process responses from Scalyr raising appropriate exceptions if needed
def handle_response(response)
    @logger.debug "Response Code: #{response.code}"
    @logger.debug "Response Body: #{response.body}"
    response_hash = Hash.new
    begin
      response_hash = LogStash::Json.load(response.body)
    rescue
      response_hash["status"] = "Invalid JSON response from server"
    end
    if !response_hash.key? "status"
      @logger.debug "JSON response does not contain status message"
      raise ServerError.new "JSON response does not contain status message"
    end
    status = response_hash["status"]
    if status != "success"
      if status =~ /discardBuffer/
        raise RequestDroppedError.new(status, response.code, @add_events_uri, response.body)
      else
        raise ServerError.new(status, response.code, @add_events_uri, response.body)
      end
    else
      code = response.code.to_s.strip.to_i
      if code < 200 or code > 299
        raise ServerError.new(status, response.code, @add_events_uri, response.body)
      end
    end
    response
  end
def handle_response ( response ) @logger . debug "Response Code: #{response.code}" @logger . debug "Response Body: #{response.body}" response_hash = Hash . new begin response_hash = LogStash :: Json . load ( response . body ) rescue response_hash [ "status" ] = "Invalid JSON response from server" end if ! response_hash . key? "status" @logger . debug "JSON response does not contain status message" raise ServerError . new "JSON response does not contain status message" end status = response_hash [ "status" ] if status != "success" if status =~ / discardBuffer / raise RequestDroppedError . new ( status , response . code , @add_events_uri , response . body ) else raise ServerError . new ( status , response . code , @add_events_uri , response . body ) end else code = response . code . to_s . strip . to_i if code < 200 or code > 299 raise ServerError . new ( status , response . code , @add_events_uri , response . body ) end end response end
Process responses from Scalyr, raising appropriate exceptions if needed
Process responses from Scalyr raising appropriate exceptions if needed
# make sure the JSON response has a "status" field
response