Class: Eco::API::Session::Batch::Errors
- Inherits:
-
Object
- Object
- Eco::API::Session::Batch::Errors
- 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
entrieswith errortype. -
#count ⇒ Integer
The number of
entriesthat got error.
Messaging methods collapse
Instance Method Summary collapse
-
#errors ⇒ Array<Eco::API::Session::Batch::Errors::ErrorCache>
For all the
entrieswith errors generates anArrayofErrorCacheobjects. -
#initialize(status:) ⇒ Errors
constructor
A new instance of Errors.
- #person_ref(entry) ⇒ Object
Constructor Details
Instance Attribute Details
#status ⇒ Object (readonly)
9 10 11 |
# File 'lib/eco/api/session/batch/errors.rb', line 9 def status @status end |
Instance Method Details
#any? ⇒ Boolean
Was there any Sever (reply) error as a result of this batch?
56 57 58 |
# File 'lib/eco/api/session/batch/errors.rb', line 56 def any? queue.any? {|query| !status[query].success?} end |
#by_type(only_entries: true) ⇒ Hash
Groups entries with error type
64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/eco/api/session/batch/errors.rb', line 64 def by_type(only_entries: true) errors.group_by do |e| e.type end.transform_values do |arr| if only_entries arr.map {|e| e.entry} else arr end end end |
#count ⇒ Integer
Returns the number of entries that got error.
50 51 52 |
# File 'lib/eco/api/session/batch/errors.rb', line 50 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 |
# File 'lib/eco/api/session/batch/errors.rb', line 83 def errors entries.each_with_object([]) do |entry, arr| response = status[entry] if body = response.body errs = [] if errs = body["errors"] || body["error"] errs = [errs].flatten(1).compact end if errs.empty? && !response.success? errs = [body["response"]].flatten(1).compact end errs.each do |msg| arr.push(ErrorCache.new( klass = Eco::API::Error.get_type(msg), klass.new(err_msg: msg, entry: entry, session: session), entry, response )) end end end end |
#logger ⇒ Object
42 43 44 |
# File 'lib/eco/api/session/batch/errors.rb', line 42 def logger status.logger end |
#message ⇒ Object
108 109 110 111 112 113 114 115 |
# File 'lib/eco/api/session/batch/errors.rb', line 108 def msgs = strs if msgs.length > 0 "There were #{msgs.length} errors:\n" + msgs.join("\n") else "There were no errors for the current batch '#{method}'!! ;)" end end |
#method ⇒ Object
27 28 29 |
# File 'lib/eco/api/session/batch/errors.rb', line 27 def method status.method end |
#person_ref(entry) ⇒ Object
127 128 129 |
# File 'lib/eco/api/session/batch/errors.rb', line 127 def person_ref(entry) Eco::API::Session::Batch::Feedback.person_ref(entry) end |
#print ⇒ Object
117 118 119 120 121 122 123 124 |
# File 'lib/eco/api/session/batch/errors.rb', line 117 def print msgs = strs if msgs.length > 0 logger.error("There were #{msgs.length} errors:\n" + msgs.join("\n")) else logger.info("There were no errors for the current batch '#{method}'!! ;)") end end |
#queue ⇒ Object
22 23 24 |
# File 'lib/eco/api/session/batch/errors.rb', line 22 def queue status.queue end |
#session ⇒ Eco::API::Session
Returns currently active session.
38 39 40 |
# File 'lib/eco/api/session/batch/errors.rb', line 38 def session status.session end |
#to_index(*args) ⇒ Object
33 34 35 |
# File 'lib/eco/api/session/batch/errors.rb', line 33 def to_index(*args) status.to_index(*args) end |