Class: Eco::API::Session::Batch::Errors
- Includes:
- Language::AuxiliarLogger
- Defined in:
- lib/eco/api/session/batch/errors.rb
Overview
Helper object linked to a Batch::Status
. Its aim is to manage the errors of the batch status.
Defined Under Namespace
Classes: ErrorCache
Instance Attribute Summary collapse
- #status ⇒ Object readonly
Status object shortcuts collapse
- #logger ⇒ Object
- #method ⇒ Object
- #queue ⇒ Object
-
#session ⇒ Eco::API::Session
Currently active
session
. - #to_index(*args) ⇒ Object
Pure errors helper methods collapse
-
#any? ⇒ Boolean
Was there any Sever (reply) error as a result of this batch?.
-
#by_type(only_entries: true) ⇒ Hash
Groups
entries
with errortype
. -
#count ⇒ Integer
The number of
entries
that got error.
Messaging methods collapse
Instance Method Summary collapse
-
#errors ⇒ Array<Eco::API::Session::Batch::Errors::ErrorCache>
For all the
entries
with errors generates anArray
ofErrorCache
objects. -
#initialize(status:) ⇒ Errors
constructor
A new instance of Errors.
- #person_ref(entry) ⇒ Object
Methods included from Language::AuxiliarLogger
Constructor Details
#initialize(status:) ⇒ Errors
Returns a new instance of Errors.
15 16 17 18 19 20 |
# File 'lib/eco/api/session/batch/errors.rb', line 15 def initialize(status:) msg = "Expected Batch::Status as root. Given: #{status.class}" raise ArgumentError msg unless status.is_a?(Eco::API::Session::Batch::Status) @status = status end |
Instance Attribute Details
#status ⇒ Object (readonly)
10 11 12 |
# File 'lib/eco/api/session/batch/errors.rb', line 10 def status @status end |
Instance Method Details
#any? ⇒ Boolean
Was there any Sever (reply) error as a result of this batch?
60 61 62 |
# File 'lib/eco/api/session/batch/errors.rb', line 60 def any? queue.any? {|query| !status[query].success?} end |
#by_type(only_entries: true) ⇒ Hash
Groups entries
with error type
68 69 70 71 72 73 74 |
# File 'lib/eco/api/session/batch/errors.rb', line 68 def by_type(only_entries: true) errors.group_by(&:type).transform_values do |arr| next arr unless only_entries arr.map(&:entry) end end |
#count ⇒ Integer
Returns the number of entries
that got error.
53 54 55 |
# File 'lib/eco/api/session/batch/errors.rb', line 53 def count entries.length end |
#errors ⇒ Array<Eco::API::Session::Batch::Errors::ErrorCache>
For all the entries
with errors generates an Array
of ErrorCache
objects
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 |
# File 'lib/eco/api/session/batch/errors.rb', line 83 def errors entries.each_with_object([]) do |entry, arr| response = status[entry] next unless (body = response.body) errs = [] case body when Hash body_errs = body["errors"] || body["error"] errs = [body_errs].flatten(1).compact if body_errs response_errs = errs.empty? && !response.success? errs = [body["response"]].flatten(1).compact if response_errs when String errs = [body] end errs.each do |msg| err_cache = ErrorCache.new( klass = Eco::API::Error.get_type(msg), klass.new(err_msg: msg, entry: entry, session: session), entry, response ) arr.push(err_cache) end end end |
#logger ⇒ Object
45 46 47 |
# File 'lib/eco/api/session/batch/errors.rb', line 45 def logger status.logger || super end |
#message ⇒ Object
115 116 117 118 119 120 121 122 123 |
# File 'lib/eco/api/session/batch/errors.rb', line 115 def msgs = strs if msgs.empty? "There were no errors for the current batch '#{method}'!! ;) " else "There were #{msgs.length} errors:\n" + msgs.join("\n") end end |
#method ⇒ Object
30 31 32 |
# File 'lib/eco/api/session/batch/errors.rb', line 30 def method status.method end |
#person_ref(entry) ⇒ Object
140 141 142 |
# File 'lib/eco/api/session/batch/errors.rb', line 140 def person_ref(entry) Eco::API::Session::Batch::Feedback.person_ref(entry) end |
#print ⇒ Object
125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/eco/api/session/batch/errors.rb', line 125 def print msgs = strs if msgs.empty? log(:info) { "There were no errors for the current batch '#{method}'!! ;) " } else msg = "There were #{msgs.length} errors:\n" msg << msgs.join("\n") log(:error) { msg } end end |
#queue ⇒ Object
25 26 27 |
# File 'lib/eco/api/session/batch/errors.rb', line 25 def queue status.queue end |
#session ⇒ Eco::API::Session
Returns currently active session
.
41 42 43 |
# File 'lib/eco/api/session/batch/errors.rb', line 41 def session status.session end |
#to_index(*args) ⇒ Object
36 37 38 |
# File 'lib/eco/api/session/batch/errors.rb', line 36 def to_index(*args) status.to_index(*args) end |