Class: LedgerSync::Ledgers::TestLedger::Util::ErrorMatcher
- Inherits:
-
Object
- Object
- LedgerSync::Ledgers::TestLedger::Util::ErrorMatcher
- Defined in:
- lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb
Direct Known Subclasses
LedgerErrorParser::AuthenticationMatcher, LedgerErrorParser::AuthorizationMatcher, LedgerErrorParser::ClientMatcher, LedgerErrorParser::ThrottleMatcher, OperationErrorParser::DuplicateNameMatcher, OperationErrorParser::GenericMatcher, OperationErrorParser::NotFoundMatcher, OperationErrorParser::ValidationError
Instance Attribute Summary collapse
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#message ⇒ Object
readonly
Returns the value of attribute message.
Instance Method Summary collapse
- #body ⇒ Object
-
#code ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
-
#detail ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
- #error_class ⇒ Object
-
#error_message ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity.
-
#initialize(error:) ⇒ ErrorMatcher
constructor
A new instance of ErrorMatcher.
- #match? ⇒ Boolean
- #output_message ⇒ Object
Constructor Details
#initialize(error:) ⇒ ErrorMatcher
Returns a new instance of ErrorMatcher.
11 12 13 14 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 11 def initialize(error:) @error = error @message = error..to_s end |
Instance Attribute Details
#error ⇒ Object (readonly)
Returns the value of attribute error.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 8 def error @error end |
#message ⇒ Object (readonly)
Returns the value of attribute message.
8 9 10 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 8 def @message end |
Instance Method Details
#body ⇒ Object
16 17 18 19 20 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 16 def body error.response.body rescue NoMethodError nil end |
#code ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
41 42 43 44 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 41 def code # rubocop:disable Metrics/CyclomaticComplexity ((body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('code')) || (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('code'))).to_i end |
#detail ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
36 37 38 39 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 36 def detail # rubocop:disable Metrics/CyclomaticComplexity (body && JSON.parse(body).dig('fault', 'error')&.first&.fetch('detail')) || (body && JSON.parse(body).dig('Fault', 'Error')&.first&.fetch('Detail')) end |
#error_class ⇒ Object
22 23 24 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 22 def error_class raise NotImplementedError end |
#error_message ⇒ Object
rubocop:disable Metrics/CyclomaticComplexity
26 27 28 29 30 31 32 33 34 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 26 def # rubocop:disable Metrics/CyclomaticComplexity return error. unless body parsed_body = JSON.parse(body) parsed_body.dig('fault', 'error')&.first&.fetch('message') || parsed_body.dig('Fault', 'Error')&.first&.fetch('Message') || parsed_body['error'] end |
#match? ⇒ Boolean
46 47 48 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 46 def match? raise NotImplementedError end |
#output_message ⇒ Object
50 51 52 |
# File 'lib/ledger_sync/test/support/test_ledger/util/error_matcher.rb', line 50 def raise NotImplementedError end |