Sha256: ae368a82fe2ae4e84457ea132bd1069ee094ab9a58260e1c7627cc82fd8bbf3f

Contents?: true

Size: 887 Bytes

Versions: 2

Compression:

Stored size: 887 Bytes

Contents

# frozen_string_literal: true

module ActiveCampaign
  class Error < RuntimeError # :nodoc:
    def initialize(response = nil, exception = nil)
      super

      self.response = response
      @exception = exception
    end

    def message
      if response.nil?
        super
      else
        <<~MESSAGE
          STATUS: #{response.status}
          URL: #{env.url}
          REQUEST HEADERS: #{env.request_headers}
          RESPONSE_HEADERS: #{env.response_headers}
          REQUEST_BODY: #{env.request_body}\n\n"
          RESPONSE_BODY: #{response.body}\n\n"
        MESSAGE
      end
    end

    private

    def env
      @env ||= response.env
    end

    attr_accessor :response
  end

  class ClientError < Error
  end

  class UnauthorizedError < ClientError
  end

  class ResourceNotFound < ClientError
  end

  class UnprocessableEntityError < ClientError
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ractive_campaign-0.1.0 lib/active_campaign/api_errors.rb
ractive_campaign-0.0.1 lib/active_campaign/api_errors.rb