lib/eco/api/session/batch/errors.rb in eco-helpers-2.1.10 vs lib/eco/api/session/batch/errors.rb in eco-helpers-2.1.11
- old
+ new
@@ -79,20 +79,26 @@
# 1. `type` -> the error type `Class`
# 2. `err` -> an instance object of that error `class` type
# 3. `entry` -> the entry that generated the error
# 4. `response` -> the original response from the server that carries the error
def errors
+ require 'byebug'
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
+ case body
+ when Hash
+ if errs = (body["errors"] || body["error"])
+ errs = [errs].flatten(1).compact
+ end
+ if errs.empty? && !response.success?
+ errs = [body["response"]].flatten(1).compact
+ end
+ when String
+ errs = [body]
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,
@@ -176,10 +182,10 @@
msg = ""
unless status.success?(key)
i = to_index(key)
entry = queue.to_a[i]
response = status[i]
- msg = "Error #{response.status}: #{response.body}\n"
+ msg = "Error #{response.status} (#{response.status.reason}): #{response.body}\n"
msg += "-- Failed to batch #{method}. Person: #{person_ref(entry)}"
end
msg
end