From e6b26c7ed4fe973a9583e5fb7fe79c19b08b5b2b Mon Sep 17 00:00:00 2001 From: Jeremy Friesen Date: Thu, 24 Mar 2022 08:16:28 -0400 Subject: [PATCH] Favoring re-use of authorization error (#16992) We only have one reference to the UnauthorizedError, which is shadows the ApplicationPolicy::NotAuthorizedError. This commit removes the exception. Related to forem/forem#16985 but only barely --- app/controllers/api/v0/analytics_controller.rb | 4 ++-- app/errors/unauthorized_error.rb | 1 - 2 files changed, 2 insertions(+), 3 deletions(-) delete mode 100644 app/errors/unauthorized_error.rb diff --git a/app/controllers/api/v0/analytics_controller.rb b/app/controllers/api/v0/analytics_controller.rb index 163c3a3aa..2e3188894 100644 --- a/app/controllers/api/v0/analytics_controller.rb +++ b/app/controllers/api/v0/analytics_controller.rb @@ -4,7 +4,7 @@ module Api respond_to :json rescue_from ArgumentError, with: :error_unprocessable_entity - rescue_from UnauthorizedError, with: :error_unauthorized + rescue_from ApplicationPolicy::NotAuthorizedError, with: :error_unauthorized before_action :authenticate_with_api_key_or_current_user! before_action :authorize_user_organization @@ -49,7 +49,7 @@ module Api return unless analytics_params[:organization_id] @org = Organization.find_by(id: analytics_params[:organization_id]) - raise UnauthorizedError unless @org && @user.org_member?(@org) + raise ApplicationPolicy::NotAuthorizedError unless @org && @user.org_member?(@org) end def load_owner diff --git a/app/errors/unauthorized_error.rb b/app/errors/unauthorized_error.rb deleted file mode 100644 index 6bc84a127..000000000 --- a/app/errors/unauthorized_error.rb +++ /dev/null @@ -1 +0,0 @@ -class UnauthorizedError < StandardError; end