Skip to content

Commit 50455b9

Browse files
authored
Better Error Response (#4524)
LastOperationFailedState error changed with ApiError, ApiError is thrown in failed status during service instance update and create and added to the service binding create/delete
1 parent 00a4564 commit 50455b9

13 files changed

+17
-18
lines changed

app/actions/v3/service_binding_create.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ def poll(binding)
5353
raise LastOperationFailedState
5454
end
5555
rescue LastOperationFailedState => e
56-
raise e
56+
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', 'create', e.message)
5757
rescue StandardError => e
5858
save_failed_state(binding, e)
5959
raise e

app/actions/v3/service_binding_delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def poll(binding)
6060
raise LastOperationFailedState
6161
end
6262
rescue LastOperationFailedState => e
63-
raise e
63+
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', 'delete', e.message)
6464
rescue StandardError => e
6565
update_last_operation(binding, state: 'failed', description: e.message)
6666
raise e

app/actions/v3/service_instance_create_managed.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,6 @@ def provision(instance, parameters: {}, accepts_incomplete: false)
7373
end
7474
rescue StandardError => e
7575
save_failed_state(instance, e)
76-
7776
raise e
7877
end
7978

@@ -100,7 +99,7 @@ def poll(instance)
10099
raise LastOperationFailedState.new(last_operation_result[:last_operation][:description])
101100
end
102101
rescue LastOperationFailedState => e
103-
raise e
102+
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', 'create managed', e.message)
104103
rescue StandardError => e
105104
save_failed_state(instance, e)
106105
raise e

app/actions/v3/service_instance_update_managed.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ def update(accepts_incomplete: false)
113113
end
114114
rescue StandardError => e
115115
save_failed_state(service_instance, e)
116-
117116
raise e
118117
end
119118

@@ -140,7 +139,7 @@ def poll
140139
raise LastOperationFailedState.new(details[:last_operation][:description])
141140
end
142141
rescue LastOperationFailedState => e
143-
raise e
142+
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', 'update', e.message)
144143
rescue StandardError => e
145144
save_failed_state(service_instance, e)
146145
raise e

app/jobs/v3/create_binding_async_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,10 @@ def perform
6666
finish if polling_status[:finished]
6767

6868
self.polling_interval_seconds = polling_status[:retry_after] if polling_status[:retry_after].present?
69+
rescue CloudController::Errors::ApiError => e
70+
raise e
6971
rescue OperationCancelled => e
7072
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', operation_type, e.message)
71-
rescue BindingNotFound => e
72-
raise e
7373
rescue ServiceBindingCreate::BindingNotRetrievable
7474
raise CloudController::Errors::ApiError.new_from_details('ServiceBindingInvalid', 'The broker responded asynchronously but does not support fetching binding data')
7575
rescue StandardError => e

app/jobs/v3/delete_binding_job.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ def perform
5555
return finish if polling_status[:finished]
5656

5757
self.polling_interval_seconds = polling_status[:retry_after] if polling_status[:retry_after].present?
58+
rescue CloudController::Errors::ApiError => e
59+
raise e
5860
rescue StandardError => e
5961
save_failure(e.message) if binding.reload.last_operation.state != 'failed' && !e.is_a?(V3::ServiceRouteBindingDelete::ConcurrencyError)
6062
raise CloudController::Errors::ApiError.new_from_details('UnableToPerform', 'unbind', e.message)

spec/support/shared_examples/v3_service_binding_create.rb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
require 'db_spec_helper'
1+
require 'spec_helper'
22
require 'services/service_brokers/v2/errors/service_broker_bad_response'
33
require 'services/service_brokers/v2/errors/service_broker_request_rejected'
44
require 'cloud_controller/http_request_error'
@@ -207,7 +207,7 @@ class BadError < StandardError; end
207207
let(:state) { 'failed' }
208208

209209
it 'updates the last operation' do
210-
expect { action.poll(binding) }.to raise_error(VCAP::CloudController::V3::LastOperationFailedState)
210+
expect { action.poll(binding) }.to raise_error(CloudController::Errors::ApiError)
211211

212212
binding.reload
213213
expect(binding.last_operation.state).to eq('failed')
@@ -371,7 +371,7 @@ class BadError < StandardError; end
371371
let(:state) { 'failed' }
372372

373373
it 'does not create an audit event' do
374-
expect { action.poll(binding) }.to raise_error(VCAP::CloudController::V3::LastOperationFailedState)
374+
expect { action.poll(binding) }.to raise_error(CloudController::Errors::ApiError)
375375

376376
expect(binding_event_repo).not_to have_received(:record_create)
377377
end

spec/support/shared_examples/v3_service_binding_delete.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ class BadError < StandardError; end
255255
let(:state) { 'failed' }
256256

257257
it 'updates the last operation' do
258-
expect { action.poll(binding) }.to raise_error(VCAP::CloudController::V3::LastOperationFailedState)
258+
expect { action.poll(binding) }.to raise_error(CloudController::Errors::ApiError)
259259

260260
binding.reload
261261
expect(binding.last_operation.state).to eq('failed')

spec/unit/actions/service_credential_binding_delete_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ module V3
134134
let(:state) { 'failed' }
135135

136136
it 'does not create an audit event' do
137-
expect { action.poll(binding) }.to raise_error(VCAP::CloudController::V3::LastOperationFailedState)
137+
expect { action.poll(binding) }.to raise_error(CloudController::Errors::ApiError)
138138

139139
expect(klass.first).to eq(binding)
140140
expect(binding_event_repo).not_to have_received(:record_delete)

spec/unit/actions/service_route_binding_create_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ module V3
450450
let(:state) { 'failed' }
451451

452452
it 'does not notify diego or create an audit event' do
453-
expect { action.poll(binding) }.to raise_error(VCAP::CloudController::V3::LastOperationFailedState)
453+
expect { action.poll(binding) }.to raise_error(CloudController::Errors::ApiError)
454454

455455
expect(messenger).not_to have_received(:send_desire_request)
456456
expect(binding_event_repo).not_to have_received(:record_create)

0 commit comments

Comments
 (0)