Sha256: fc2cc42cabd1a72ed863d216bb98c4f787c82d97580d388bbd4ffad534149b59

Contents?: true

Size: 1.67 KB

Versions: 9

Compression:

Stored size: 1.67 KB

Contents

module Rack
  module OAuth2
    module Server
      module Abstract
        class Error < StandardError
          attr_accessor :status, :error, :description, :uri, :realm

          def initialize(status, error, description = nil, options = {})
            @status      = status
            @error       = error
            @description = description
            @uri         = options[:uri]
            @realm       = options[:realm]
            super [error, description].compact.join(' :: ')
          end

          def protocol_params
            {
              :error             => error,
              :error_description => description,
              :error_uri         => uri
            }
          end

          def finish
            response = Rack::Response.new
            response.status = status
            yield response if block_given?
            unless response.redirect?
              response.header['Content-Type'] = 'application/json'
              response.write Util.compact_hash(protocol_params).to_json
            end
            response.finish
          end
        end

        class BadRequest < Error
          def initialize(error = :bad_request, description = nil, options = {})
            super 400, error, description, options
          end
        end

        class Unauthorized < Error
          def initialize(error = :unauthorized, description = nil, options = {})
            super 401, error, description, options
          end
        end

        class Forbidden < Error
          def initialize(error = :forbidden, description = nil, options = {})
            super 403, error, description, options
          end
        end
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
rack-oauth2-0.8.3 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.8.2 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.8.1 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.8.0 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.8.0.alpha lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.7.0 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.6.9 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.6.8 lib/rack/oauth2/server/abstract/error.rb
rack-oauth2-0.6.7 lib/rack/oauth2/server/abstract/error.rb