lib/moneta/api/runtime_exception.rb in moneta-api-1.7.0 vs lib/moneta/api/runtime_exception.rb in moneta-api-1.8.0
- old
+ new
@@ -1,5 +1,28 @@
module Moneta
module Api
- class RuntimeException < Exception; end
+ class RuntimeException < Exception
+ attr_reader :code, :detail
+
+ def initialize(code, message, detail)
+ super(message)
+
+ @code = code
+ @detail = detail
+ end
+
+ def inspect
+ error = [ "#{ @code }: #{ message }" ]
+ error += detail.collect { |key, value| "#{ key }: #{ Array(value).join($/) }" }
+ error.join($/)
+ end
+
+ def to_hash
+ {
+ code: code,
+ message: message,
+ detail: detail
+ }
+ end
+ end
end
end