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 9d63d31
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -8,6 +8,7 @@ User-visible changes worth mentioning.
## main

- [#PR ID] Add your changelog here.
- [#1691] Make new Doorkeeper errors backward compatible with older extensions.

## 5.6.8

Expand Down
16 changes: 14 additions & 2 deletions lib/doorkeeper/oauth/error_response.rb
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 9d63d31

Please sign in to comment.