Skip to content

Commit c5b8e1e

Browse files
committed
handle not found error when getting an object
1 parent 93708ef commit c5b8e1e

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

lib/fog/aliyun/models/storage/files.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,17 @@ def get(key)
8484
_start = (i - 1) * Excon::CHUNK_SIZE
8585
_end = i * Excon::CHUNK_SIZE - 1
8686
range = "#{_start}-#{_end}"
87-
data = service.get_object(object, range)
88-
chunk = data[:body]
87+
begin
88+
data = service.get_object(object, range)
89+
chunk = data[:body]
90+
rescue StandardError => error
91+
case error.response.body
92+
when %r{<Code>NoSuchKey</Code>},%r{<Code>SymlinkTargetNotExist</Code>}
93+
chunk = ''
94+
else
95+
raise(error)
96+
end
97+
end
8998
yield(chunk)
9099
body = nil
91100
end

0 commit comments

Comments
 (0)