lib/rdstation/error/formatter.rb in rdstation-ruby-client-2.8.1 vs lib/rdstation/error/formatter.rb in rdstation-ruby-client-2.8.2

- old
+ new

@@ -3,12 +3,13 @@ require_relative './format' module RDStation class Error class Formatter - def initialize(error_response) + def initialize(error_response, headers = {}) @error_response = error_response + @headers = headers end def to_array return @error_response unless @error_response.is_a?(Hash) @@ -28,17 +29,17 @@ errors end def from_single_hash error_hash = @error_response.dup - error_message = error_hash.delete('error') + error_message = error_hash.delete('error') || error_hash.delete('message') [ { 'error_type' => 'TOO_MANY_REQUESTS', 'error_message' => error_message, - 'details' => error_hash + 'details' => error_hash.key?('max') ? error_hash : error_details } ] end def from_flat_hash @@ -99,9 +100,17 @@ attribute_name = errors.first attribute_errors = errors.last errors = build_error_from_array(attribute_name, attribute_errors) array_of_errors.push(*errors) end + end + + def error_details + { + max: @headers.fetch('ratelimit-limit-quotas', 0), + usage: @headers.fetch('ratelimit-limit-quotas', 0), + remaining_time: @headers.fetch('retry-after-quotas', 0) + } end end end end