Sha256: dbea17df67fb5eee3dd5d3d90d0bb3920a2a81c37b6198d371001a6e5413d44f

Contents?: true

Size: 1.53 KB

Versions: 1

Compression:

Stored size: 1.53 KB

Contents

# frozen_string_literal: true

module Minty
  class Exception < StandardError
    attr_reader :error_data

    def initialize(message, error_data = {})
      super(message)
      @error_data = error_data
    end
  end

  class HTTPError < Minty::Exception
    def http_headers
      error_data[:headers]
    end

    def http_code
      error_data[:code]
    end

    def http_response
      JSON.parse(to_s)
    end

    def message
      http_response['message']
    end
  end

  class Unauthorized < Minty::HTTPError; end
  class NotFound < Minty::HTTPError; end
  class Unsupported < Minty::HTTPError; end
  class ServerError < Minty::HTTPError; end
  class BadRequest < Minty::HTTPError; end
  class RequestTimeout < Minty::Exception; end
  class MissingUserId < Minty::Exception; end
  class MissingClientId < Minty::Exception; end
  class MissingOrganizationId < Minty::Exception; end
  class MissingActionName < Minty::Exception; end
  class MissingActionId < Minty::Exception; end
  class MissingExecutionId < Minty::Exception; end
  class MissingTriggerId < Minty::Exception; end
  class MissingParameter < Minty::Exception; end
  class MissingVersionId < Minty::Exception; end
  class AccessDenied < Minty::HTTPError; end
  class InvalidParameter < Minty::Exception; end
  class InvalidCredentials < Minty::Exception; end
  class InvalidApiNamespace < Minty::Exception; end

  class RateLimitEncountered < Minty::HTTPError
    def reset
      Time.at(Integer(headers[:x_ratelimit_reset])).utc
    end
  end

  class InvalidIdToken < Minty::Exception; end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
minty-1.0.1 lib/minty/exception.rb