@@ -35,14 +35,14 @@ private async Task<Token> RetrieveTokenAsync(string grantType, CancellationToken
35
35
{
36
36
result . EnsureSuccessStatusCode ( ) ;
37
37
return Token . FromTokenResponse (
38
- await result . Content . ReadFromJsonAsync < TokenResponse > ( cancellationToken ) ?? throw new HttpRequestException ( Translations . INVALID_OR_UNEXPECTED_RESPONSE , null , result . StatusCode ) ,
38
+ await result . Content . ReadFromJsonAsync < TokenResponse > ( cancellationToken ) ?? throw new ExtendedHttpRequestException ( Translations . INVALID_OR_UNEXPECTED_RESPONSE , null , result . StatusCode ) ,
39
39
_timeprovider . GetUtcNow ( )
40
40
) ;
41
41
}
42
42
catch ( HttpRequestException ex )
43
43
{
44
- var err = await result . Content . ReadFromJsonAsync < ErrorResponse > ( cancellationToken ) ?? throw new HttpRequestException ( Translations . INVALID_OR_UNEXPECTED_RESPONSE , null , result . StatusCode ) ;
45
- throw new HttpRequestException ( $ "[{ err . Error } ] { err . Description } ", ex , result . StatusCode ) ;
44
+ var err = await result . Content . ReadFromJsonAsync < ErrorResponse > ( cancellationToken ) ?? throw new ExtendedHttpRequestException ( Translations . INVALID_OR_UNEXPECTED_RESPONSE , null , result . StatusCode ) ;
45
+ throw new ExtendedHttpRequestException ( $ "[{ err . Error } ] { err . Description } ", ex , result . StatusCode ) ;
46
46
}
47
47
}
48
48
@@ -76,7 +76,7 @@ private async Task<Token> RefreshTokenAsync(Token token, CancellationToken cance
76
76
return await RetrieveTokenAsync ( GrantTypes . Refresh , cancellationToken ) ;
77
77
}
78
78
}
79
- catch ( HttpRequestException ex ) when ( ex . StatusCode is HttpStatusCode . BadRequest or HttpStatusCode . Unauthorized ) { }
79
+ catch ( ExtendedHttpRequestException ex ) when ( ex . StatusCode is HttpStatusCode . BadRequest or HttpStatusCode . Unauthorized ) { }
80
80
// Refresh token expired or refresh failed? Try to get a new token
81
81
return await RetrieveTokenAsync ( GetGrantType ( ) , cancellationToken ) . ConfigureAwait ( false ) ;
82
82
}
@@ -99,4 +99,9 @@ private record ErrorResponse
99
99
[ property: JsonPropertyName ( "error" ) ] string Error ,
100
100
[ property: JsonPropertyName ( "error_description" ) ] string Description
101
101
) ;
102
- }
102
+
103
+ private class ExtendedHttpRequestException ( string message , Exception ? innerException , HttpStatusCode httpStatusCode ) : HttpRequestException ( message , innerException )
104
+ {
105
+ public HttpStatusCode StatusCode { get ; private set ; } = httpStatusCode ;
106
+ }
107
+ }
0 commit comments