Sha256: 5067532f9416ddf566c298b2f60d8421fde202bb6fb70163099bdd24a83d51f5

Contents?: true

Size: 800 Bytes

Versions: 20

Compression:

Stored size: 800 Bytes

Contents

module QuickTravel
  class AdapterError < StandardError
    attr_reader :response
    attr_reader :status

    def initialize(response)
      case response
        when String
          @response = { 'error' => response }
          @status = 422
        when HTTParty::Response
          @response = response.parsed_response
          @status = response.code
        else
          fail "Unexpected response type #{response.class}"\
               "Should be String or HTTParty::Response"
      end

      error_message = if @response.is_a? Hash
        @response.fetch('error', "We're sorry, but something went wrong. Please call us.")
      else
        @response
      end
      super(error_message)
    end

    def error_type
      @response.fetch('error_type', 'unspecified')
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
quicktravel_client-4.7.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.6.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.5.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.4.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.3.2 lib/quick_travel/adapter_error.rb
quicktravel_client-4.3.1 lib/quick_travel/adapter_error.rb
quicktravel_client-4.3.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.2.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.1.0 lib/quick_travel/adapter_error.rb
quicktravel_client-4.0.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.9.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.8.1 lib/quick_travel/adapter_error.rb
quicktravel_client-3.8.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.7.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.6.1 lib/quick_travel/adapter_error.rb
quicktravel_client-3.6.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.5.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.4.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.3.0 lib/quick_travel/adapter_error.rb
quicktravel_client-3.2.0 lib/quick_travel/adapter_error.rb