Sha256: 4a60cf3177e1cc40815e7a1dce72d087ecb1bbbd190e161403a15f30c62d3cac

Contents?: true

Size: 624 Bytes

Versions: 1

Compression:

Stored size: 624 Bytes

Contents

# frozen_string_literal: true

module FriendlyShipping
  module Services
    class UpsFreight
      class RestfulApiErrorHandler
        extend Dry::Monads::Result::Mixin

        def self.call(error)
          parsed_json = JSON.parse(error.response.body)
          errors = parsed_json.dig('response', 'errors')

          failure_string = errors.map do |err|
            status = err['code']
            desc = err['message']
            [status, desc].compact.join(": ").presence || 'UPS could not process the request.'
          end.join("\n")

          Failure(failure_string)
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
friendly_shipping-0.5.3 lib/friendly_shipping/services/ups_freight/restful_api_error_handler.rb