Sha256: 7cf72d7d695a117d7008890c9cced5b83b77ed2a0181dc564a8b700b9f779eab

Contents?: true

Size: 1.38 KB

Versions: 22

Compression:

Stored size: 1.38 KB

Contents

module Garage
  class HTTPError < ::StandardError
    attr_accessor :status
    def status_code
      Rack::Utils.status_code(status)
    end
  end

  class BadRequest < HTTPError
    def initialize(error)
      @status = :bad_request
      super(error)
    end
  end

  class Unauthorized < HTTPError
    attr_reader :user, :action, :resource_class, :scopes

    def initialize(user, action, resource_class, status = :forbidden, scopes = [])
      @user, @action, @resource_class, @status, @scopes = user, action, resource_class, status, scopes

      if scopes.empty?
        super "Authorized user is not allowed to take the requested operation #{action} on #{resource_class}"
      else
        super "Insufficient scope to process the requested operation. Missing scope(s): #{scopes.join(", ")}"
      end
    end
  end

  class PermissionError < Unauthorized; end
  class MissingScopeError < Unauthorized; end

  class AuthBackendTimeout < HTTPError
    def initialize(open_timeout, read_timeout)
      @status = :internal_server_error
      super("Auth backend timed out: open_timeout=#{open_timeout}, read_timeout=#{read_timeout}")
    end
  end

  class AuthBackendError < HTTPError
    attr_reader :response

    def initialize(response)
      @status = :internal_server_error
      @response = response
      super("Auth backend responded error: status=#{response.status_code}")
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
the_garage-2.8.2 lib/garage/exceptions.rb
the_garage-2.8.1 lib/garage/exceptions.rb
the_garage-2.8.0 lib/garage/exceptions.rb
the_garage-2.7.0 lib/garage/exceptions.rb
the_garage-2.6.1 lib/garage/exceptions.rb
the_garage-2.6.0 lib/garage/exceptions.rb
the_garage-2.5.0 lib/garage/exceptions.rb
the_garage-2.4.4 lib/garage/exceptions.rb
the_garage-2.4.3 lib/garage/exceptions.rb
the_garage-2.4.2 lib/garage/exceptions.rb
the_garage-2.4.1 lib/garage/exceptions.rb
the_garage-2.4.0 lib/garage/exceptions.rb
the_garage-2.3.3 lib/garage/exceptions.rb
the_garage-2.3.2 lib/garage/exceptions.rb
the_garage-2.3.1 lib/garage/exceptions.rb
the_garage-2.3.0 lib/garage/exceptions.rb
the_garage-2.2.0 lib/garage/exceptions.rb
the_garage-2.1.0 lib/garage/exceptions.rb
the_garage-2.0.3 lib/garage/exceptions.rb
the_garage-2.0.2 lib/garage/exceptions.rb