Skip to content

Commit

Permalink
Fix exception class handling for release token model
Browse files Browse the repository at this point in the history
The location of the exception class definition
was wrong and therefore an uninitialized constant error
was thrown by the release token model.

The naming of the exception class did not quite fit
as well.
  • Loading branch information
krauselukas authored and Dany Marcoux committed Apr 26, 2021
1 parent 358fcfb commit 6a7d4a8
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/api/app/controllers/trigger/errors.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,4 @@ class InvalidToken < APIError
403,
'No valid token found'
end

class NoPermissionForPackage < APIError
end
end
2 changes: 2 additions & 0 deletions src/api/app/models/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ class Token < ApplicationRecord

validates :user, presence: true

include Token::Errors

def token_name
self.class.token_name
end
Expand Down
7 changes: 7 additions & 0 deletions src/api/app/models/token/errors.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Token::Errors
extend ActiveSupport::Concern

class NoReleaseTargetFound < APIError
setup 404
end
end
5 changes: 1 addition & 4 deletions src/api/app/models/token/release.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ def self.token_name

def call(_options)
manual_release_targets = package_from_association_or_params.project.release_targets.where(trigger: 'manual')
unless manual_release_targets.any?
raise NoPermissionForPackage.setup('not_found', 404,
"#{package_from_association_or_params.project} has no release targets that are triggered manually")
end
raise NoReleaseTargetFound, "#{package_from_association_or_params.project} has no release targets that are triggered manually" unless manual_release_targets.any?

manual_release_targets.each do |release_target|
release_package(package_from_association_or_params,
Expand Down

0 comments on commit 6a7d4a8

Please sign in to comment.