Class: Radiator::ErrorParser
- Inherits:
-
Object
- Object
- Radiator::ErrorParser
- Includes:
- Utils
- Defined in:
- lib/radiator/error_parser.rb
Constant Summary collapse
- REPREPARE =
[ 'is_canonical( c ): signature is not canonical', 'now < trx.expiration: ', '(skip & skip_transaction_dupe_check) || trx_idx.indices().get<by_trx_id>().find(trx_id) == trx_idx.indices().get<by_trx_id>().end(): Duplicate transaction check failed' ]
Instance Attribute Summary collapse
-
#api_method ⇒ Object
readonly
Returns the value of attribute api_method.
-
#api_name ⇒ Object
readonly
Returns the value of attribute api_name.
-
#api_params ⇒ Object
readonly
Returns the value of attribute api_params.
-
#can_reprepare ⇒ Object
(also: #can_reprepare?)
readonly
Returns the value of attribute can_reprepare.
-
#can_retry ⇒ Object
(also: #can_retry?)
readonly
Returns the value of attribute can_retry.
-
#debug ⇒ Object
readonly
Returns the value of attribute debug.
-
#error_code ⇒ Object
readonly
Returns the value of attribute error_code.
-
#error_message ⇒ Object
readonly
Returns the value of attribute error_message.
-
#expiry ⇒ Object
(also: #expiry?)
readonly
Returns the value of attribute expiry.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
Instance Method Summary collapse
-
#initialize(response) ⇒ ErrorParser
constructor
A new instance of ErrorParser.
- #parse_error_response ⇒ Object
- #to_s ⇒ Object
Methods included from Utils
#error, #extract_signatures, #hexlify, #pakArr, #pakC, #pakHash, #pakI, #pakL!, #pakS, #pakStr, #pakc, #paks, #send_log, #unhexlify, #varint, #warning
Constructor Details
#initialize(response) ⇒ ErrorParser
Returns a new instance of ErrorParser.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/radiator/error_parser.rb', line 19 def initialize(response) @response = response @error_code = nil @error_message = nil @api_name = nil @api_method = nil @api_params = nil @expiry = nil @can_retry = nil @can_reprepare = nil @debug = nil parse_error_response end |
Instance Attribute Details
#api_method ⇒ Object (readonly)
Returns the value of attribute api_method.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def api_method @api_method end |
#api_name ⇒ Object (readonly)
Returns the value of attribute api_name.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def api_name @api_name end |
#api_params ⇒ Object (readonly)
Returns the value of attribute api_params.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def api_params @api_params end |
#can_reprepare ⇒ Object (readonly) Also known as: can_reprepare?
Returns the value of attribute can_reprepare.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def can_reprepare @can_reprepare end |
#can_retry ⇒ Object (readonly) Also known as: can_retry?
Returns the value of attribute can_retry.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def can_retry @can_retry end |
#debug ⇒ Object (readonly)
Returns the value of attribute debug.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def debug @debug end |
#error_code ⇒ Object (readonly)
Returns the value of attribute error_code.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def error_code @error_code end |
#error_message ⇒ Object (readonly)
Returns the value of attribute error_message.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def @error_message end |
#expiry ⇒ Object (readonly) Also known as: expiry?
Returns the value of attribute expiry.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def expiry @expiry end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
5 6 7 |
# File 'lib/radiator/error_parser.rb', line 5 def response @response end |
Instance Method Details
#parse_error_response ⇒ Object
36 37 38 39 40 41 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 |
# File 'lib/radiator/error_parser.rb', line 36 def parse_error_response return if response.nil? @error_code = response['error']['data']['code'] stacks = response['error']['data']['stack'] 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' } @error_message = stack_formats.reject(&:empty?).join('; ') @api_name, @api_method, @api_params = if !!data_call_method @api_name = data_call_method['call.params'] end case @error_code when 10 @expiry = false @can_retry = false @can_reprepare = if @api_name == 'network_broadcast_api' (stack_formats & REPREPARE).any? else false end when 4030100 # Code 4030100 is "transaction_expiration_exception: transaction # expiration exception". If we assume the expiration was valid, the # node might be bad and needs to be dropped. @expiry = true @can_retry = true @can_reprepare = false when 4030200 # Code 4030200 is "transaction tapos exception". They are recoverable # if the transaction hasn't expired yet. A tapos exception can be # retried in situations where the node is behind and the tapos is # based on a block the node doesn't know about yet. @expiry = false @can_retry = true # Allow fall back to reprepare if retry fails. @can_reprepare = true else @expiry = false @can_retry = false @can_reprepare = false end end |
#to_s ⇒ Object
86 87 88 89 90 91 92 |
# File 'lib/radiator/error_parser.rb', line 86 def to_s if !! && !.empty? "#{error_code}: #{}" else error_code.to_s end end |