summaryrefslogtreecommitdiff
path: root/lib/error.rb
diff options
context:
space:
mode:
authormguetlein <martin.guetlein@gmail.com>2011-02-02 17:11:24 +0100
committermguetlein <martin.guetlein@gmail.com>2011-02-02 17:11:24 +0100
commit70aee6e9dfece2760fc6d616e7151f41cc7625bf (patch)
tree311649a1e05b42bab8c259068623f4508e080f6d /lib/error.rb
parent3aaae5a3fe341073fc0537606aababe387d830e0 (diff)
resclient wrapper: headers <-> payload, error report from rdf
Diffstat (limited to 'lib/error.rb')
-rw-r--r--lib/error.rb41
1 files changed, 27 insertions, 14 deletions
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