lib/hyper_resource/exceptions.rb in hyperresource-0.1.9.3 vs lib/hyper_resource/exceptions.rb in hyperresource-0.1.9.4
- old
+ new
@@ -1,12 +1,24 @@
class HyperResource
class Exception < ::Exception
- attr_accessor :response # response object which led to this exception
- attr_accessor :cause # internal exception which led to this exception
+ attr_accessor :response # Response body which led to this
+ attr_accessor :response_object # Response object which led to this
+ attr_accessor :cause # Internal exception which led to this
def initialize(message, opts={})
self.response = opts[:response]
+ self.response_object = opts[:response_object]
self.cause = opts[:cause]
+
+ ## Try to help out with the message
+ if self.response_object
+ if error = self.response_object['error']
+ message = "#{message} (#{error})"
+ end
+ elsif self.response
+ message = "#{message} (\"#{self.response.inspect}\")"
+ end
+
super(message)
end
end
class ResponseError < Exception; end