Sha256: c982369937237aa7d6d97dfcdf39baec5e71b985d146807a296b76d7c53dfa95

Contents?: true

Size: 1.15 KB

Versions: 22

Compression:

Stored size: 1.15 KB

Contents

module EventbriteSDK
  class EventbriteAPIError < RuntimeError
    attr_reader :message, :response

    def initialize(msg = '', response = :none)
      @message = msg
      @response = response
    end

    # Returns a hash with AT LEAST 'error_description'.
    # When an error is raised manually there will be no response!
    # This is handled by using the specified message as the error_description.
    def parsed_error
      default = %({"error_description": "#{message}"})
      value = response_value(:body, fallback: default)

      JSON.parse(value)
    end

    # Returns the status code of the response, or :none if there is no response.
    def status_code
      response_value(:code)
    end

    private

    def response_value(key, fallback: :none)
      if response.respond_to?(key)
        response.send(key)
      else
        fallback
      end
    end
  end

  class BadRequest < EventbriteAPIError; end
  class Forbidden < EventbriteAPIError; end
  class InvalidAttribute < EventbriteAPIError; end
  class InternalServerError < EventbriteAPIError; end
  class ResourceNotFound < EventbriteAPIError; end
  class Unauthorized < EventbriteAPIError; end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
eventbrite_sdk-3.6.0 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.4.0 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.3.1 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.3.0 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.2.0 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.6 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.5 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.4 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.3 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.2 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.1 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.1.0 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.11 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.10 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.9 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.8 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.7 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.6 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.5 lib/eventbrite_sdk/exceptions.rb
eventbrite_sdk-3.0.4 lib/eventbrite_sdk/exceptions.rb