Skip to content

Commit ffd7508

Browse files
authored
Merge branch 'main' into wangbill/dedup
2 parents 2c1ee61 + ad96233 commit ffd7508

File tree

1 file changed

+23
-11
lines changed

1 file changed

+23
-11
lines changed

src/Extensions/AzureBlobPayloads/PayloadStore/BlobPayloadStore.cs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
// Licensed under the MIT License.
33

44
using System.IO.Compression;
5+
using System.Net;
56
using System.Text;
7+
using Azure;
68
using Azure.Core;
79
using Azure.Storage.Blobs;
810
using Azure.Storage.Blobs.Models;
@@ -117,20 +119,30 @@ public override async Task<string> DownloadAsync(string token, CancellationToken
117119

118120
BlobClient blob = this.containerClient.GetBlobClient(name);
119121

120-
using BlobDownloadStreamingResult result = await blob.DownloadStreamingAsync(cancellationToken: cancellationToken);
121-
Stream contentStream = result.Content;
122-
bool isGzip = string.Equals(
123-
result.Details.ContentEncoding, ContentEncodingGzip, StringComparison.OrdinalIgnoreCase);
122+
try
123+
{
124+
using BlobDownloadStreamingResult result = await blob.DownloadStreamingAsync(cancellationToken: cancellationToken);
125+
Stream contentStream = result.Content;
126+
bool isGzip = string.Equals(
127+
result.Details.ContentEncoding, ContentEncodingGzip, StringComparison.OrdinalIgnoreCase);
128+
129+
if (isGzip)
130+
{
131+
using GZipStream decompressed = new(contentStream, CompressionMode.Decompress);
132+
using StreamReader reader = new(decompressed, Encoding.UTF8);
133+
return await ReadToEndAsync(reader, cancellationToken);
134+
}
124135

125-
if (isGzip)
136+
using StreamReader uncompressedReader = new(contentStream, Encoding.UTF8);
137+
return await ReadToEndAsync(uncompressedReader, cancellationToken);
138+
}
139+
catch (RequestFailedException ex) when (ex.Status == (int)HttpStatusCode.NotFound)
126140
{
127-
using GZipStream decompressed = new(contentStream, CompressionMode.Decompress);
128-
using StreamReader reader = new(decompressed, Encoding.UTF8);
129-
return await ReadToEndAsync(reader, cancellationToken);
141+
throw new InvalidOperationException(
142+
$"The blob '{name}' was not found in container '{container}'. " +
143+
"The payload may have been deleted or the container was never created.",
144+
ex);
130145
}
131-
132-
using StreamReader uncompressedReader = new(contentStream, Encoding.UTF8);
133-
return await ReadToEndAsync(uncompressedReader, cancellationToken);
134146
}
135147

136148
/// <inheritdoc/>

0 commit comments

Comments
 (0)