42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
# File 'lib/radiator/error_parser.rb', line 42
def parse_error_response
if response.nil?
@expiry = false
@can_retry = false
@can_reprepare = false
return
end
@response = JSON[response] if response.class == String
@error = if !!@response['error']
response['error']
else
response
end
begin
if !!@error['data']
@error_code = @error['data']['code']
stacks = @error['data']['stack']
stack_formats = nil
@error_message = if !!stacks
stack_formats = stacks.map { |s| s['format'] }
stack_datum = stacks.map { |s| s['data'] }
data_call_method = stack_datum.find { |data| data['call.method'] == 'call' }
data_trx_ix = stack_datum.find { |data| !!data['trx_ix'] }
@trx_id = data_trx_ix['trx_ix'] if !!data_trx_ix
stack_formats.reject(&:empty?).join('; ')
else
@error_code ||= @error['code']
@error['message']
end
@api_name, @api_method, @api_params = if !!data_call_method
@api_name = data_call_method['call.params']
end
else
@error_code = @error['code']
@error_message = @error['message']
@expiry = false
@can_retry = false
@can_reprepare = false
end
case @error_code
when -32603
if error_match?('Internal Error')
@expiry = false
@can_retry = true
@can_reprepare = true
end
when -32003
if error_match?('Unable to acquire database lock')
@expiry = false
@can_retry = true
@can_reprepare = true
end
when -32000
@expiry = false
@can_retry = coerce_backtrace
@can_reprepare = if @api_name == 'network_broadcast_api'
error_match(REPREPARE_WHITELIST)
else
false
end
when 10
@expiry = false
@can_retry = coerce_backtrace
@can_reprepare = !!stack_formats && (stack_formats & REPREPARE_WHITELIST).any?
when 13
@error_message = @error['data']['message']
@expiry = false
@can_retry = false
@can_reprepare = false
when 3030000
@error_message = @error['data']['message']
@expiry = false
@can_retry = false
@can_reprepare = false
when 4030100
@expiry = true
@can_retry = true
@can_reprepare = false
when 4030200
@expiry = false
@can_retry = true
@can_reprepare = true
else
@expiry = false
@can_retry = false
@can_reprepare = false
end
rescue => e
if defined? ap
if ENV['DEBUG'] == 'true'
ap error_parser_exception: e, original_response: response, backtrace: e.backtrace
else
ap error_parser_exception: e, original_response: response
end
end
@expiry = false
@can_retry = false
@can_reprepare = false
end
end
|