Sha256: 668365a32dbb8548d241550c6b35f7886dda9efa44da29ba4970a5922d22c94c
Contents?: true
Size: 841 Bytes
Versions: 6
Compression:
Stored size: 841 Bytes
Contents
# frozen_string_literal: true module FriendlyShipping module Services class UpsFreight class RestfulApiErrorHandler extend Dry::Monads::Result::Mixin def self.call(error, original_request: nil, original_response: nil) 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( ApiFailure.new( failure_string, original_request: original_request, original_response: original_response ) ) end end end end end
Version data entries
6 entries across 6 versions & 1 rubygems