Sha256: 4d016f878069eff3a05746a2d87693401cf6158aca6bb1e6f0ea32cfd8dc9956
Contents?: true
Size: 960 Bytes
Versions: 2
Compression:
Stored size: 960 Bytes
Contents
# frozen_string_literal: true module FriendlyShipping module Services class RL # Raised when an R+L API error is returned. class ApiError < FriendlyShipping::ApiError # @param cause [RestClient::Exception] the cause of the error def initialize(cause) super(cause, parse_message(cause)) end private # Parses the message from the error response. # # @param error [RestClient::Exception] the cause of the error # @return [String, nil] the message or nil if it couldn't be parsed def parse_message(error) return error.message unless error.response && error.http_code == 400 parsed_body = JSON.parse(error.response.body) messages = parsed_body.fetch('Errors')&.map { |e| e.fetch('ErrorMessage') } messages&.join(', ') rescue JSON::ParserError, KeyError => _e nil end end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
friendly_shipping-0.10.1 | lib/friendly_shipping/services/rl/api_error.rb |
friendly_shipping-0.10.0 | lib/friendly_shipping/services/rl/api_error.rb |