Skip to content

Commit

Permalink
Make new errors backward compatible
Browse files Browse the repository at this point in the history
Fixes #1685
  • Loading branch information
nbulaj committed Feb 12, 2024
1 parent 6633934 commit 3721514
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions lib/doorkeeper/oauth/error_response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,26 @@ class ErrorResponse < BaseResponse
def self.from_request(request, attributes = {})
new(
attributes.merge(
name: request.error&.name_for_response,
exception_class: request.error,
name: error_name_for(request.error),
exception_class: exception_class_for(request.error),
state: request.try(:state),
redirect_uri: request.try(:redirect_uri),
),
)
end

def self.error_name_for(error)
error.respond_to?(:name_for_response) ? error.name_for_response : error
end

def self.exception_class_for(error)
return error if error.respond_to?(:name_for_response)

"Doorkeeper::Errors::#{error.to_s.classify}".safe_constantize
end

private_class_method :error_name_for, :exception_class_for

delegate :name, :description, :state, to: :@error

def initialize(attributes = {})
Expand Down

0 comments on commit 3721514

Please sign in to comment.