Skip to content

Commit

Permalink
refactor error mesg + function params
Browse files Browse the repository at this point in the history
  • Loading branch information
kathap committed Feb 13, 2025
1 parent 7665514 commit 4dd08b6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 15 deletions.
22 changes: 11 additions & 11 deletions app/controllers/v3/service_instances_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,8 @@ def create_user_provided(message)
def create_managed(message, space:)
service_plan = ServicePlan.first(guid: message.service_plan_guid)
unprocessable_service_plan! unless service_plan_valid?(service_plan)
unavailable_service_plan!(service_plan.name, service_plan.guid) unless service_plan_active?(service_plan)
service_plan_not_visible_in_space!(service_plan.name, service_plan.guid, space.name, space.guid) \
unless service_plan_exists_in_space?(service_plan, space)
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, space)

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

service_plan = ServicePlan.first(guid: message.service_plan_guid)
unprocessable_service_plan! unless service_plan_valid?(service_plan)
unavailable_service_plan!(service_plan.name, service_plan.guid) unless service_plan_active?(service_plan)
service_plan_not_visible_in_space!(service_plan.name, service_plan.guid, space.name, space.guid) \
unless service_plan_exists_in_space?(service_plan, service_instance.space)
unavailable_service_plan!(service_plan) unless service_plan_active?(service_plan)
service_plan_not_visible_in_space!(service_plan, space) unless service_plan_exists_in_space?(service_plan, service_instance.space)
invalid_service_plan_relation! unless service_plan.service == service_instance.service
end

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

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

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

def invalid_service_plan_relation!
Expand Down
10 changes: 6 additions & 4 deletions spec/request/service_instances_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1260,8 +1260,10 @@ def check_filtered_instances(*instances)
expect(last_response).to have_status_code(422)
expect(parsed_response['errors']).to include(
include({
'detail' => "Invalid service plan. Ensure that the service plan '#{service_plan.name}' with \
guid '#{service_plan_guid}' is visible in your current space '#{space.name}' with guid '#{space.guid}'.",
'detail' => 'Invalid service plan. This could be due to a space-scoped broker which is offering the service plan ' \
"'#{service_plan.name}' with guid '#{service_plan.guid} in another space or that the plan " \
'is not enabled in this organization. Ensure that the service plan is visible in your current space ' \
"'#{space.name}' with guid '#{space.guid}'.",
'title' => 'CF-UnprocessableEntity',
'code' => 10_008
})
Expand All @@ -1278,7 +1280,7 @@ def check_filtered_instances(*instances)
expect(parsed_response['errors']).to include(
include({
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
"has been removed from the service broker's catalog." \
"has been removed from the service broker's catalog. " \
'It is not possible to create new service instances using this plan.',
'title' => 'CF-UnprocessableEntity',
'code' => 10_008
Expand Down Expand Up @@ -2417,7 +2419,7 @@ def check_filtered_instances(*instances)
expect(parsed_response['errors']).to include(
include({
'detail' => "Invalid service plan. The service plan '#{service_plan.name}' with guid '#{service_plan.guid}' " \
"has been removed from the service broker's catalog." \
"has been removed from the service broker's catalog. " \
'It is not possible to create new service instances using this plan.',
'title' => 'CF-UnprocessableEntity',
'code' => 10_008
Expand Down

0 comments on commit 4dd08b6

Please sign in to comment.