From 70aee6e9dfece2760fc6d616e7151f41cc7625bf Mon Sep 17 00:00:00 2001 From: mguetlein Date: Wed, 2 Feb 2011 17:11:24 +0100 Subject: resclient wrapper: headers <-> payload, error report from rdf --- lib/error.rb | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) (limited to 'lib/error.rb') diff --git a/lib/error.rb b/lib/error.rb index 8c666f3..49756d5 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -18,6 +18,10 @@ module OpenTox class NotFoundError < RuntimeError def http_code; 404; end end + + class ServiceUnavailableError < RuntimeError + def http_code; 503; end + end class RestCallError < RuntimeError attr_accessor :rest_params @@ -28,18 +32,31 @@ module OpenTox # TODO replace params with URIs (errorCause -> OT.errorCause) attr_reader :message, :actor, :errorCause, :http_code, :errorDetails, :errorType + + private + def initialize( http_code, erroType, message, actor, errorCause, rest_params=nil, backtrace=nil ) + @http_code = http_code + @errorType = erroType + @message = message + @actor = actor + @errorCause = errorCause + @rest_params = rest_params + @backtrace = backtrace + end + public # creates a error report object, from an ruby-exception object - # @param [Exception] error - # @param [String] actor, URI of the call that cause the error - def initialize( error, actor ) - @http_code = error.http_code - @errorType = error.class.to_s - @message = error.message - @actor = actor - @errorCause = error.errorCause if error.errorCause - @rest_params = error.rest_params if error.is_a?(OpenTox::RestCallError) and error.rest_params - @backtrace = error.backtrace.short_backtrace if CONFIG[:backtrace] + # @param [Exception] error + # @param [String] actor, URI of the call that cause the error + def self.create( error, actor ) + rest_params = error.rest_params if error.is_a?(OpenTox::RestCallError) and error.rest_params + backtrace = error.backtrace.short_backtrace if CONFIG[:backtrace] + ErrorReport.new( error.http_code, error.class.to_s, error.message, actor, error.errorCause, rest_params, backtrace ) + end + + def self.from_rdf(rdf) + metadata = OpenTox::Parser::Owl.metadata_from_rdf( rdf, OT.ErrorReport ) + ErrorReport.new(metadata[OT.statusCode], metadata[OT.errorCode], metadata[OT.message], metadata[OT.actor], metadata[OT.errorCause]) end # overwrite sorting to make easier readable @@ -61,10 +78,6 @@ module OpenTox c[OT.errorCause] = @errorCause.rdf_content if @errorCause c end - - def self.from_rdf(rdf) - raise "not yet implemented" - end def to_rdfxml s = Serializer::Owl.new -- cgit v1.2.3