class FriendlyShipping::Services::ShipEngine::BadRequest

Attributes

response[R]
rest_error[R]

Public Class Methods

new(rest_error) click to toggle source
Calls superclass method
# File lib/friendly_shipping/services/ship_engine/bad_request.rb, line 11
def initialize(rest_error)
  @rest_error = rest_error
  @response = rest_error.response
  super parse_json_errors || rest_error
end

Private Instance Methods

parse_json_errors() click to toggle source
# File lib/friendly_shipping/services/ship_engine/bad_request.rb, line 19
def parse_json_errors
  parsed_body = JSON.parse(response.body)
  messages = parsed_body.fetch('errors')&.map { |e| e.fetch('message') }
  messages&.join(', ')
rescue JSON::ParserError, KeyError => _e
  nil
end