Skip to content

Commit 4dd08b6

Browse files
committed
refactor error mesg + function params
1 parent 7665514 commit 4dd08b6

File tree

2 files changed

+17
-15
lines changed

2 files changed

+17
-15
lines changed

app/controllers/v3/service_instances_controller.rb

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -255,9 +255,8 @@ def create_user_provided(message)
255255
def create_managed(message, space:)
256256
service_plan = ServicePlan.first(guid: message.service_plan_guid)
257257
unprocessable_service_plan! unless service_plan_valid?(service_plan)
258-
unavailable_service_plan!(service_plan.name, service_plan.guid) unless service_plan_active?(service_plan)
259-
service_plan_not_visible_in_space!(service_plan.name, service_plan.guid, space.name, space.guid) \
260-
unless service_plan_exists_in_space?(service_plan, space)
258+
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
259+
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, space)
261260

262261
action = V3::ServiceInstanceCreateManaged.new(user_audit_info, message.audit_hash)
263262
VCAP::CloudController::ManagedServiceInstance.db.transaction do
@@ -415,9 +414,8 @@ def raise_if_invalid_service_plan!(service_instance, message)
415414

416415
service_plan = ServicePlan.first(guid: message.service_plan_guid)
417416
unprocessable_service_plan! unless service_plan_valid?(service_plan)
418-
unavailable_service_plan!(service_plan.name, service_plan.guid) unless service_plan_active?(service_plan)
419-
service_plan_not_visible_in_space!(service_plan.name, service_plan.guid, space.name, space.guid) \
420-
unless service_plan_exists_in_space?(service_plan, service_instance.space)
417+
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
418+
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, service_instance.space)
421419
invalid_service_plan_relation! unless service_plan.service == service_instance.service
422420
end
423421

@@ -437,14 +435,16 @@ def unprocessable_service_plan!
437435
unprocessable!('Invalid service plan. Ensure that the service plan exists, is available, and you have access to it.')
438436
end
439437

440-
def unavailable_service_plan!(service_plan, service_plan_guid)
441-
unprocessable!("Invalid service plan. The service plan '#{service_plan}' with guid '#{service_plan_guid}' has been removed from the service broker's catalog." \
438+
def unavailable_service_plan!(service_plan)
439+
unprocessable!("Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' has been removed from the service broker's catalog. " \
442440
'It is not possible to create new service instances using this plan.')
443441
end
444442

445-
def service_plan_not_visible_in_space!(service_plan, service_plan_guid, space_name, space_guid)
446-
unprocessable!("Invalid service plan. Ensure that the service plan '#{service_plan}' with guid '#{service_plan_guid}' \
447-
is visible in your current space '#{space_name}' with guid '#{space_guid}'.")
443+
def service_plan_not_visible_in_space!(service_plan, space)
444+
unprocessable!('Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
445+
"'#{service_plan.name}' with guid '#{service_plan.guid} in another space or that the plan " \
446+
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
447+
"'#{space.name}' with guid '#{space.guid}'.")
448448
end
449449

450450
def invalid_service_plan_relation!

spec/request/service_instances_spec.rb

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1260,8 +1260,10 @@ 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 '#{service_plan.name}' with \
1264-
guid '#{service_plan_guid}' is visible in your current space '#{space.name}' with guid '#{space.guid}'.",
1263+
'detail' => 'Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
1264+
"'#{service_plan.name}' with guid '#{service_plan.guid} in another space or that the plan " \
1265+
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
1266+
"'#{space.name}' with guid '#{space.guid}'.",
12651267
'title' => 'CF-UnprocessableEntity',
12661268
'code' => 10_008
12671269
})
@@ -1278,7 +1280,7 @@ def check_filtered_instances(*instances)
12781280
expect(parsed_response['errors']).to include(
12791281
include({
12801282
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
1281-
"has been removed from the service broker's catalog." \
1283+
"has been removed from the service broker's catalog. " \
12821284
'It is not possible to create new service instances using this plan.',
12831285
'title' => 'CF-UnprocessableEntity',
12841286
'code' => 10_008
@@ -2417,7 +2419,7 @@ def check_filtered_instances(*instances)
24172419
expect(parsed_response['errors']).to include(
24182420
include({
24192421
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
2420-
"has been removed from the service broker's catalog." \
2422+
"has been removed from the service broker's catalog. " \
24212423
'It is not possible to create new service instances using this plan.',
24222424
'title' => 'CF-UnprocessableEntity',
24232425
'code' => 10_008

0 commit comments

Comments
 (0)