summaryrefslogtreecommitdiff
path: root/lib/error.rb
blob: 8a57bd0a2e8e40f64ed073d9e8cf1660614295ae (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

# adding additional fields to Exception class to format errors according to OT-API
class Exception
  attr_accessor :errorCause
  def http_code; 500; end
end

module OpenTox
  
  class BadRequestError < RuntimeError
    def http_code; 400; end
  end
  
  class NotAuthorizedError < RuntimeError
    def http_code; 401; end
  end
  
  class NotFoundError < RuntimeError
    def http_code; 404; end
  end
  
  class RestCallError < RuntimeError
    attr_accessor :rest_params
    def http_code; 502; end
  end

  class ErrorReport
    
    # TODO replace params with URIs (errorCause -> OT.errorCause)
    attr_reader :message, :actor, :errorCause, :http_code, :errorDetails, :errorType
    
    # 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
    end

    def self.from_rdf(rdf)
      raise "not yet implemented"
    end
    
    def self.to_rdf
      raise "not yet implemented"
    end
  end
end