Skip to content

Commit 5a6d9ca

Browse files
author
Dustin Tsang
committed
Fixes #6971,bz1085417 - api handle nonexistent id
In capsule and product APIs, the show action for a nonexistant id fails to give a proper 404. for example /api/products/123123 where product 123132 does not exist product gives 500 no resource loaded capsule gives protected method `resource_name' called for
1 parent 71d9d2b commit 5a6d9ca

File tree

2 files changed

+6
-5
lines changed

2 files changed

+6
-5
lines changed

app/controllers/katello/api/v2/capsules_controller.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ def show
2929
super
3030
end
3131

32+
def resource_name
33+
:smart_proxy
34+
end
35+
3236
protected
3337

3438
def resource_class
3539
SmartProxy
3640
end
3741

38-
def resource_name
39-
:smart_proxy
40-
end
41-
4242
def authorized
4343
User.current.allowed_to?(params.slice(:action, :id).merge(controller: 'api/v2/smart_proxies'))
4444
end

app/controllers/katello/api/v2/products_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,8 @@ def sync
109109
protected
110110

111111
def find_product
112-
@product = Product.find_by_id(params[:id]) if params[:id]
112+
@product = Product.find_by_id(params[:id])
113+
fail HttpErrors::NotFound, _("Couldn't find product '%s'") % params[:id] unless @product
113114
end
114115

115116
def find_activation_key

0 commit comments

Comments
 (0)