From 0e759bee80e2668e1fec7b741a4ea18015f98b84 Mon Sep 17 00:00:00 2001 From: mguetlein Date: Fri, 21 Jan 2011 11:52:53 +0100 Subject: simplify error handling once again, and adding http code --- lib/error.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'lib/error.rb') diff --git a/lib/error.rb b/lib/error.rb index b72ce7e..e47ad62 100644 --- a/lib/error.rb +++ b/lib/error.rb @@ -1,22 +1,27 @@ # adding additional fields to Exception class to format errors according to OT-API class Exception - attr_accessor :creator, :errorCause, :id + attr_accessor :creator, :errorCause, :id, :http_code + def http_code; 500; end end module OpenTox - class NotAuthorizedError < Exception + class BadRequestError < Exception + def http_code; 400; end end - class NotFoundError < Exception + class NotAuthorizedError < Exception + def http_code; 401; end end - class BadRequestError < Exception + class NotFoundError < Exception + def http_code; 404; end end class RestCallError < Exception - attr_accessor :code, :body, :uri, :payload, :headers + attr_accessor :rest_code, :rest_body, :rest_uri, :rest_payload, :rest_headers + def http_code; 502; end end class ErrorReport @@ -30,6 +35,9 @@ module OpenTox def self.format(error, request=nil, response=nil) # sets current uri error.creator = "#{request.env['rack.url_scheme']}://#{request.env['HTTP_HOST']}#{request.env['REQUEST_URI']}" if request + # bit of a hack: set instance attribute in order to add it for the to_yaml conversion + error.http_code = error.http_code + accept = request.env['HTTP_ACCEPT'].to_s if request case accept # when /rdf/ -- cgit v1.2.3