Sha256: cce6e344e77c46076bd04b67a341bc8fe81b769f1766145b7b74ee616c6f5238

Contents?: true

Size: 866 Bytes

Versions: 6

Compression:

Stored size: 866 Bytes

Contents

# frozen_string_literal: true

# EasyPost Error object.
class EasyPost::Error < StandardError
  attr_reader :message, :status, :http_body, :code, :errors

  # Initialize a new EasyPost Error
  def initialize(message = nil, status = nil, code = nil, errors = nil, http_body = nil)
    # message should be a string but can sometimes incorrectly come back as an array
    @message = message.is_a?(Array) ? message.join(', ') : message
    @status = status
    @code = code
    @errors = errors
    @http_body = http_body

    super(message)
  end

  # Convert an error to a string.
  def to_s
    "#{code} (#{status}): #{message} #{errors}".strip
  end

  # Compare error properties.
  def ==(other)
    other.is_a?(EasyPost::Error) &&
      message == other.message &&
      status == other.status &&
      code == other.code &&
      errors == other.errors
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
easypost-4.13.0 lib/easypost/error.rb
easypost-4.12.0 lib/easypost/error.rb
easypost-4.11.0 lib/easypost/error.rb
easypost-4.10.0 lib/easypost/error.rb
easypost-4.9.0 lib/easypost/error.rb
easypost-4.8.1 lib/easypost/error.rb