Skip to content

Commit 233b1b2

Browse files
long-wan-epjim80net
authored andcommitted
fix: update error handling for restore
1 parent aaa3d9e commit 233b1b2

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

lib/datadog_backup/dashboards.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ def backup
2222
Concurrent::Promises.zip(*futures).value!
2323
end
2424

25+
def get_by_id(id)
26+
begin
27+
dashboard = except(get(id))
28+
rescue Faraday::ResourceNotFound => e
29+
dashboard = {}
30+
end
31+
except(dashboard)
32+
end
33+
2534
def initialize(options)
2635
super(options)
2736
@banlist = %w[modified_at url].freeze

lib/datadog_backup/resources.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,7 @@ def restore(id)
110110
body = load_from_file_by_id(id)
111111
begin
112112
update(id, body)
113-
rescue RuntimeError => e
114-
raise e.message unless e.message.include?('update failed with error 404')
115-
113+
rescue Faraday::ResourceNotFound => e
116114
create_newly(id, body)
117115
end
118116
end

spec/datadog_backup/core_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
allow(resources).to receive(:api_resource_name).and_return('api-resource-name-string')
104104
stubs.get('/api/api-version-string/api-resource-name-string/abc-123-def') { respond_with200({ 'test' => 'ok' }) }
105105
stubs.get('/api/api-version-string/api-resource-name-string/bad-123-id') do
106-
[404, {}, { 'error' => 'blahblah_not_found' }]
106+
raise Faraday::ResourceNotFound
107107
end
108108
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
109109
end
@@ -126,7 +126,7 @@
126126
before do
127127
allow(resources).to receive(:load_from_file_by_id).and_return({ 'load' => 'ok' })
128128
stubs.put('/api/api-version-string/api-resource-name-string/bad-123-id') do
129-
[404, {}, { 'error' => 'id not found' }]
129+
raise Faraday::ResourceNotFound
130130
end
131131
stubs.post('/api/api-version-string/api-resource-name-string', { 'load' => 'ok' }) do
132132
respond_with200({ 'id' => 'my-new-id' })

spec/datadog_backup/synthetics_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@
231231

232232
before do
233233
synthetics.write_file(synthetics.dump({ 'name' => 'restore-invalid-id', 'type' => 'api' }), synthetics.filename('restore-invalid-id'))
234-
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { [404, {}, ''] }
234+
stubs.put('/api/v1/synthetics/tests/api/restore-invalid-id') { raise Faraday::ResourceNotFound }
235235
stubs.post('/api/v1/synthetics/tests/api') { respond_with200({ 'public_id' => 'restore-valid-id' }) }
236236
allow(synthetics).to receive(:create).and_call_original
237237
allow(synthetics).to receive(:all).and_return([api_test, browser_test, { 'public_id' => 'restore-valid-id', 'type' => 'api' }])

0 commit comments

Comments
 (0)