lib/akamai_ccu/response.rb in akamai_ccu-1.5.7 vs lib/akamai_ccu/response.rb in akamai_ccu-1.5.8
- old
+ new
@@ -1,14 +1,16 @@
+require "logger"
require "time"
module AkamaiCCU
class Response
BAD_STATUS = 400
attr_reader :body, :title, :status, :detail, :support_id, :purge_id, :decribed_by, :completion_at
- def initialize(body = {}, time = Time.now)
+ def initialize(body: {}, time: Time.now, logger: Logger.new(nil))
+ @logger = logger
@body = parse(body)
@title = @body["title"]
@status = @body.fetch("httpStatus") { @body.fetch("status", BAD_STATUS) }
@detail = @body["detail"]
@support_id = @body.fetch("supportId") { @body["requestId"] }
@@ -34,8 +36,10 @@
end
private def parse(body)
return body if body.is_a? Hash
JSON.parse(body)
+ rescue JSON::ParserError => e
+ @logger.error { "reponse parse error: #{e.message}" }
end
end
end