akamsteeg / AtleX.HaveIBeenPwned

A fully async .NET Standard client library for the API of HaveIBeenPwned.com
https://www.nuget.org/packages/AtleX.HaveIBeenPwned/
MIT License
5 stars 0 forks source link

Throw exception when the CancellationToken is cancelled as soon as possible #70

Closed akamsteeg closed 1 year ago

akamsteeg commented 2 years ago

In V6 or earlier, we rely on framework code (mainly System.Text.Json or the HttpClient) to throw an exception when a supplied CancellationToken is cancelled. I think it's good form to cancel as early as possible, so we should add a cancellationToken.ThrowIfCancellationRequested() to our HaveIBeenPwnedClient.*Internal() methods after any argument and disposal checks.

⚠️ Warning: This might break user code that catches TaskCanceledException instead of OperationCanceledException. I have no idea if the HttpClient or System.Text.Json have used TaskCanceledException in the past.