Exception: Ooor::OpenERPServerError

Inherits:
RuntimeError
  • Object
show all
Defined in:
lib/ooor/errors.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(method = nil, faultCode = nil, faultString = nil, *args) ⇒ OpenERPServerError

Returns a new instance of OpenERPServerError.



39
40
41
42
43
44
45
# File 'lib/ooor/errors.rb', line 39

def initialize(method=nil, faultCode=nil, faultString=nil, *args)
  filtered_args = filter_password(args.dup())
  @request = "method: #{method} - args: #{filtered_args.inspect}"
  @faultCode = faultCode
  @faultString = faultString
  super()
end

Instance Attribute Details

#faultCodeObject

Returns the value of attribute faultCode.



3
4
5
# File 'lib/ooor/errors.rb', line 3

def faultCode
  @faultCode
end

#faultStringObject

Returns the value of attribute faultString.



3
4
5
# File 'lib/ooor/errors.rb', line 3

def faultString
  @faultString
end

#requestObject

Returns the value of attribute request.



3
4
5
# File 'lib/ooor/errors.rb', line 3

def request
  @request
end

Class Method Details

.build(faultCode, faultString, method, *args) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ooor/errors.rb', line 19

def self.build(faultCode, faultString, method, *args)
  if faultCode =~ /AttributeError: / || faultCode =~ /object has no attribute/
    return UnknownAttributeOrAssociationError.new("method: #{method} - args: #{args.inspect}", faultCode, faultString)
  elsif faultCode =~ /TypeError: /
    return TypeError.new(method, faultCode, faultString, *args)
  elsif faultCode =~ /ValueError: /
    return ValueError.new(method, faultCode, faultString, *args)
  elsif faultCode =~ /ValidateError/
    return ValidationError.new(method, faultCode, faultString, *args)
  elsif faultCode =~ /AccessDenied/ || faultCode =~ /Access Denied/ || faultCode =~ /AccessError/
    return UnAuthorizedError.new(method, faultCode, faultString, *args)
  elsif faultCode =~ /AuthenticationError: Credentials not provided/
    return InvalidSessionError.new(method, faultCode, faultString, *args)
  elsif faultCode =~ /SessionExpiredException/
    return SessionExpiredError.new(method, faultCode, faultString, *args)
  else
    return new(method, faultCode, faultString, *args)
  end
end

.create_from_trace(error, method, *args) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ooor/errors.rb', line 5

def self.create_from_trace(error, method, *args)
  begin
    #extracts the eventual error log from OpenERP response as OpenERP doesn't enforce carefully*
    #the XML/RPC spec, see https://bugs.launchpad.net/openerp/+bug/257581
    openerp_error_hash = eval("#{error}".gsub("wrong fault-structure: ", ""))
  rescue SyntaxError
  end
  if openerp_error_hash.is_a? Hash
    build(openerp_error_hash['faultCode'], openerp_error_hash['faultString'], method, *args)
  else
    return UnknownOpenERPServerError.new("method: #{method} - args: #{args.inspect}")
  end
end

Instance Method Details

#filter_password(args) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ooor/errors.rb', line 47

def filter_password(args)
  if args[0].is_a?(String) && args[2].is_a?(String) && (args[1].is_a?(Integer) || args[1].to_i != 0)
    args[2] = "####"
  end
  args.map! do |arg|
    if arg.is_a?(Hash)# && (arg.keys.index('password') || arg.keys.index(:password))
      r = {}
      arg.each do |k, v|
        if k.to_s.index('password')
          r[k] = "####"
        else
          r[k] = v
        end
      end
      r
    else
      arg
    end
  end
end

#to_sObject



68
69
70
71
72
73
74
# File 'lib/ooor/errors.rb', line 68

def to_s()
  s = super
  line = "********************************************"
  s = "\n\n#{line}\n***********     OOOR Request     ***********\n#{@request}\n#{line}\n\n"
  s << "\n#{line}\n*********** OpenERP Server ERROR ***********\n#{line}\n#{@faultCode}\n#{@faultString}\n#{line}\n."
  s
end