lib/heracles-wrapper/exceptions.rb in heracles-wrapper-0.0.1 vs lib/heracles-wrapper/exceptions.rb in heracles-wrapper-0.0.2

- old
+ new

@@ -1,11 +1,19 @@ +require 'json' module Heracles module Wrapper + DefaultErrorObject = Hash class RequestFailure < RuntimeError - attr_reader :code, :messages, :response + attr_reader :code, :errors, :response def initialize(response) @code = response.respond_to?(:code) ? response.code : 500 - @messages = response.respond_to?(:body) ? response.body : '' + begin + @errors = response.respond_to?(:body) ? + JSON.parse(response.body).fetch('errors',{}) : + {} + rescue JSON::ParserError + @errors = {"response" => "Not JSON format; See response.body"} + end @response = response super("code: #{@code}") end end class ConfigurationError < RuntimeError