diff options
author | mguetlein <martin.guetlein@gmail.com> | 2011-01-21 11:52:53 +0100 |
---|---|---|
committer | mguetlein <martin.guetlein@gmail.com> | 2011-01-21 11:52:53 +0100 |
commit | 0e759bee80e2668e1fec7b741a4ea18015f98b84 (patch) | |
tree | fa4d00fcbcaee092d5f16eb7ec785b0ed8f11f91 /lib/error.rb | |
parent | 9d06bd3024139f2bfee4722c7536ee4ffa99fe32 (diff) |
simplify error handling once again, and adding http code
Diffstat (limited to 'lib/error.rb')
-rw-r--r-- | lib/error.rb | 18 |
1 files changed, 13 insertions, 5 deletions
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/ |