Sha256: 757ecbd472daabe61f625225de4b56dc5031d94e2d539b8769cc1dff80aade27

Contents?: true

Size: 1.04 KB

Versions: 46

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Twilio
  module REST
    class TwilioError < StandardError
    end

    class RestError < TwilioError
      attr_reader :message, :response, :code, :status_code, :details, :more_info, :error_message

      def initialize(message, response)
        @status_code = response.status_code
        @code = response.body.fetch('code', @status_code)
        @details = response.body.fetch('details', nil)
        @error_message = response.body.fetch('message', nil)
        @more_info = response.body.fetch('more_info', nil)
        @message = format_message(message)
        @response = response
      end

      def to_s
        message
      end

      private

      def format_message(initial_message)
        message = "[HTTP #{status_code}] #{code} : #{initial_message}"
        message += "\n#{error_message}" if error_message
        message += "\n#{details}" if details
        message += "\n#{more_info}" if more_info
        message + "\n\n"
      end
    end

    class ObsoleteError < StandardError
    end
  end
end

Version data entries

46 entries across 46 versions & 2 rubygems

Version Path
twilio-ruby-7.0.0.pre.rc.1 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.11.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.9.1 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.9.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.8.3 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.8.2 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.8.1 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.8.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.7.1 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.7.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.6.0 lib/twilio-ruby/framework/rest/error.rb
whoosh-ruby-0.1.5 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.5.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.4.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.3.1 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.3.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.2.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.1.0 lib/twilio-ruby/framework/rest/error.rb
twilio-ruby-6.0.2 lib/twilio-ruby/framework/rest/error.rb
whoosh-ruby-0.1.4 lib/twilio-ruby/framework/rest/error.rb