Sha256: f82c2cb25ade5ca2f4315c13e425071965ba76fefbaaaec070b2e003843855e2

Contents?: true

Size: 578 Bytes

Versions: 6

Compression:

Stored size: 578 Bytes

Contents

module ShopifyAPI
  class MessageEnricher < SimpleDelegator
    def message
      return super unless (400...500).include?(code.to_i)

      @_cached_message ||= begin
        detailed_error = begin
          parsed_body = JSON.parse(body)

          if parsed_body['error']
            parsed_body['error'].to_s
          elsif parsed_body['errors']
            Array(parsed_body['errors']).join('; ')
          end
        rescue JSON::ParserError
          nil
        end

        detailed_error.present? ? "#{super} (#{detailed_error})" : super
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
shopify_api-9.2.0 lib/shopify_api/message_enricher.rb
shopify_api-9.1.0 lib/shopify_api/message_enricher.rb
shopify_api-9.0.4 lib/shopify_api/message_enricher.rb
shopify_api-9.0.3 lib/shopify_api/message_enricher.rb
shopify_api-9.0.2 lib/shopify_api/message_enricher.rb
shopify_api-9.0.1 lib/shopify_api/message_enricher.rb