diff --git a/AutoRefreshTokenHttpMessageHandler/AutoRefreshTokenHttpMessageHandler.csproj b/AutoRefreshTokenHttpMessageHandler/AutoRefreshTokenHttpMessageHandler.csproj
index eea4a72..7b0992a 100644
--- a/AutoRefreshTokenHttpMessageHandler/AutoRefreshTokenHttpMessageHandler.csproj
+++ b/AutoRefreshTokenHttpMessageHandler/AutoRefreshTokenHttpMessageHandler.csproj
@@ -1,7 +1,7 @@
- net8.0
+ netstandard2.0;netstandard2.1
enable
enable
latest
@@ -34,7 +34,14 @@
+
+
+ all
+ runtime; build; native; contentfiles; analyzers; buildtransitive
+
+
+
diff --git a/AutoRefreshTokenHttpMessageHandler/TokenAuthenticationService.cs b/AutoRefreshTokenHttpMessageHandler/TokenAuthenticationService.cs
index efb4322..65afbbf 100644
--- a/AutoRefreshTokenHttpMessageHandler/TokenAuthenticationService.cs
+++ b/AutoRefreshTokenHttpMessageHandler/TokenAuthenticationService.cs
@@ -35,14 +35,14 @@ private async Task RetrieveTokenAsync(string grantType, CancellationToken
{
result.EnsureSuccessStatusCode();
return Token.FromTokenResponse(
- await result.Content.ReadFromJsonAsync(cancellationToken) ?? throw new HttpRequestException(Translations.INVALID_OR_UNEXPECTED_RESPONSE, null, result.StatusCode),
+ await result.Content.ReadFromJsonAsync(cancellationToken) ?? throw new ExtendedHttpRequestException(Translations.INVALID_OR_UNEXPECTED_RESPONSE, null, result.StatusCode),
_timeprovider.GetUtcNow()
);
}
catch (HttpRequestException ex)
{
- var err = await result.Content.ReadFromJsonAsync(cancellationToken) ?? throw new HttpRequestException(Translations.INVALID_OR_UNEXPECTED_RESPONSE, null, result.StatusCode);
- throw new HttpRequestException($"[{err.Error}] {err.Description}", ex, result.StatusCode);
+ var err = await result.Content.ReadFromJsonAsync(cancellationToken) ?? throw new ExtendedHttpRequestException(Translations.INVALID_OR_UNEXPECTED_RESPONSE, null, result.StatusCode);
+ throw new ExtendedHttpRequestException($"[{err.Error}] {err.Description}", ex, result.StatusCode);
}
}
@@ -76,7 +76,7 @@ private async Task RefreshTokenAsync(Token token, CancellationToken cance
return await RetrieveTokenAsync(GrantTypes.Refresh, cancellationToken);
}
}
- catch (HttpRequestException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.Unauthorized) { }
+ catch (ExtendedHttpRequestException ex) when (ex.StatusCode is HttpStatusCode.BadRequest or HttpStatusCode.Unauthorized) { }
// Refresh token expired or refresh failed? Try to get a new token
return await RetrieveTokenAsync(GetGrantType(), cancellationToken).ConfigureAwait(false);
}
@@ -99,4 +99,9 @@ private record ErrorResponse
[property: JsonPropertyName("error")] string Error,
[property: JsonPropertyName("error_description")] string Description
);
-}
+
+ private class ExtendedHttpRequestException(string message, Exception? innerException, HttpStatusCode httpStatusCode) : HttpRequestException(message, innerException)
+ {
+ public HttpStatusCode StatusCode { get; private set; } = httpStatusCode;
+ }
+}
\ No newline at end of file