Skip to content

Commit 01c5174

Browse files
committed
Better error message and support logs for /v3/service_offerings and plans
1 parent e647272 commit 01c5174

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

app/controllers/v3/service_instances_controller.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ def create_user_provided(message)
254254

255255
def create_managed(message, space:)
256256
service_plan = ServicePlan.first(guid: message.service_plan_guid)
257-
unprocessable_service_plan! unless service_plan_valid?(service_plan, space)
257+
unprocessable_service_plan! unless service_plan_valid?(service_plan)
258+
service_plan_not_visible_in_space! unless resource_exists_in_space?(service_plan, space)
258259

259260
action = V3::ServiceInstanceCreateManaged.new(user_audit_info, message.audit_hash)
260261
VCAP::CloudController::ManagedServiceInstance.db.transaction do
@@ -394,17 +395,21 @@ def admin?
394395
permission_queryer.can_write_globally?
395396
end
396397

397-
def service_plan_valid?(service_plan, space)
398+
def service_plan_valid?(service_plan)
398399
service_plan &&
399-
visible_to_current_user?(plan: service_plan) &&
400-
service_plan.visible_in_space?(space)
400+
visible_to_current_user?(plan: service_plan)
401+
end
402+
403+
def resource_exists_in_space?(service_plan, space)
404+
service_plan.visible_in_space?(space)
401405
end
402406

403407
def raise_if_invalid_service_plan!(service_instance, message)
404408
return unless message.service_plan_guid
405409

406410
service_plan = ServicePlan.first(guid: message.service_plan_guid)
407-
unprocessable_service_plan! unless service_plan_valid?(service_plan, service_instance.space)
411+
unprocessable_service_plan! unless service_plan_valid?(service_plan)
412+
service_plan_not_visible_in_space! unless resource_exists_in_space?(service_plan, service_instance.space)
408413
invalid_service_plan_relation! unless service_plan.service == service_instance.service
409414
end
410415

@@ -424,6 +429,10 @@ def unprocessable_service_plan!
424429
unprocessable!('Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.')
425430
end
426431

432+
def service_plan_not_visible_in_space!
433+
unprocessable!('Invalid service plan. Ensure that the service plan is visible in your current space.')
434+
end
435+
427436
def invalid_service_plan_relation!
428437
raise CloudController::Errors::ApiError.new_from_details('InvalidRelation', 'service plan relates to a different service offering')
429438
end

spec/request/service_instances_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ def check_filtered_instances(*instances)
12601260
expect(last_response).to have_status_code(422)
12611261
expect(parsed_response['errors']).to include(
12621262
include({
1263-
'detail' => 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.',
1263+
'detail' => 'Invalid service plan. Ensure that the service plan is visible in your current space.',
12641264
'title' => 'CF-UnprocessableEntity',
12651265
'code' => 10_008
12661266
})
@@ -2413,7 +2413,7 @@ def check_filtered_instances(*instances)
24132413
expect(last_response).to have_status_code(422)
24142414
expect(parsed_response['errors']).to include(
24152415
include({
2416-
'detail' => 'Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.',
2416+
'detail' => 'Invalid service plan. Ensure that the service plan is visible in your current space.',
24172417
'title' => 'CF-UnprocessableEntity',
24182418
'code' => 10_008
24192419
})

0 commit comments

Comments
 (0)