@@ -27,39 +27,36 @@ internal static class HttpClientProgress
27
27
}
28
28
}
29
29
30
- using ( var response = await client . SendAsync ( message , HttpCompletionOption . ResponseHeadersRead ) )
30
+ using var response = await client . SendAsync ( message , HttpCompletionOption . ResponseHeadersRead ) . ConfigureAwait ( false ) ;
31
+ if ( ! response . IsSuccessStatusCode )
31
32
{
32
- if ( ! response . IsSuccessStatusCode )
33
+ var content = await response . Content . ReadAsStringAsync ( ) ;
34
+ var errorResponse = JsonConvert . DeserializeObject < ErrorResponse > ( content ) ;
35
+ var e = new SupabaseStorageException ( errorResponse ? . Message ?? content )
33
36
{
34
- var content = await response . Content . ReadAsStringAsync ( ) ;
35
- var errorResponse = JsonConvert . DeserializeObject < ErrorResponse > ( content ) ;
36
- var e = new SupabaseStorageException ( errorResponse ? . Message ?? content )
37
- {
38
- Content = content ,
39
- Response = response ,
40
- StatusCode = errorResponse ? . StatusCode ?? ( int ) response . StatusCode
41
- } ;
37
+ Content = content ,
38
+ Response = response ,
39
+ StatusCode = errorResponse ? . StatusCode ?? ( int ) response . StatusCode
40
+ } ;
42
41
43
- e . AddReason ( ) ;
44
- throw e ;
45
- }
42
+ e . AddReason ( ) ;
43
+ throw e ;
44
+ }
46
45
47
- var contentLength = response . Content . Headers . ContentLength ;
48
- using ( var download = await response . Content . ReadAsStreamAsync ( ) )
49
- {
50
- // no progress... no contentLength... very sad
51
- if ( progress is null || ! contentLength . HasValue )
52
- {
53
- await download . CopyToAsync ( destination ) ;
54
- return destination ;
55
- }
56
-
57
- // Such progress and contentLength much reporting Wow!
58
- var progressWrapper = new Progress < long > ( totalBytes => progress . Report ( GetProgressPercentage ( totalBytes , contentLength . Value ) ) ) ;
59
- await download . CopyToAsync ( destination , 81920 , progressWrapper , cancellationToken ) ;
60
- }
46
+ var contentLength = response . Content . Headers . ContentLength ;
47
+ using var download = await response . Content . ReadAsStreamAsync ( ) ;
48
+
49
+ // no progress... no contentLength... very sad
50
+ if ( progress is null || ! contentLength . HasValue )
51
+ {
52
+ await download . CopyToAsync ( destination ) ;
53
+ return destination ;
61
54
}
62
55
56
+ // Such progress and contentLength much reporting Wow!
57
+ var progressWrapper = new Progress < long > ( totalBytes => progress . Report ( GetProgressPercentage ( totalBytes , contentLength . Value ) ) ) ;
58
+ await download . CopyToAsync ( destination , 81920 , progressWrapper , cancellationToken ) ;
59
+
63
60
float GetProgressPercentage ( float totalBytes , float currentBytes ) => ( totalBytes / currentBytes ) * 100f ;
64
61
65
62
return destination ;
0 commit comments