Fail fast when Alpha Vantage refuses a request for the account - #63
Merged
thorstenalpers merged 1 commit intoSep 20, 2026
Merged
thorstenalpers merged 1 commit into
thorstenalpers merged 1 commit into
Conversation
Alpha Vantage answers a premium-only endpoint (TIME_SERIES_DAILY_ADJUSTED on a free key) with HTTP 200 and an "Information" message instead of a time series. The parser read that as invalid data and the retry policy ran through the whole back-off budget before failing. A premium-endpoint refusal or an invalid API key now throws the new FinanceNetAccessDeniedException from every Alpha Vantage call. Like FinanceNetNoDataException it derives from FinanceNetException, is not retried and is not wrapped. The invalid-key check was previously only in GetForexRecordsAsync and was retried. The rate-limit message stays retryable.
Owner
|
Thanks, great diagnosis. I reproduced it: the same call takes about 6 minutes on main and fails in under a second with your change. Merging. I'll follow up with a small fix for the negative cases in the Alpha Vantage integration tests, they use |
thorstenalpers
added a commit
that referenced
this pull request
Sep 20, 2026
* Accept derived exceptions in the Alpha Vantage integration tests Assert.ThrowsAsync matches the exact type, so the negative cases turned red once #63 made a refused request throw FinanceNetAccessDeniedException. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> * Keep an Alpha Vantage rate-limit notice retryable The notice advertises "premium endpoints", so the "premium endpoint" marker classified a temporary rate limit as a permanent refusal. The marker now matches the full sentence. The notice also lacks the old "higher API call volume" wording, so GetOverviewAsync deserialized it to an empty object and reported no data without retrying. "rate limit" is now recognised as a retryable limit in all four methods. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> --------- Co-authored-by: thorsten <thorsten@PC> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On a free Alpha Vantage key,
GetRecordsAsyncgets this reply every time:{ "Information": "Thank you for using Alpha Vantage! This is a premium endpoint. You may subscribe to any of the premium plans at https://www.alphavantage.co/premium/ to instantly unlock all premium endpoints" }It arrives with HTTP 200, so the parser read it as invalid data ("data is invalid"). The retry policy then ran through the whole back-off budget, even though retrying can never change this answer.
Changes
FinanceNetAccessDeniedException : FinanceNetException, thrown when the provider refuses the request for the account. Existingcatch (FinanceNetException)handlers keep working.AlphaVantageService.ThrowIfRejectedchecks every response from all four methods. It throws the new exception for a premium-endpoint reply or an invalid/missing API key.PollyPolicyFactorydoes not retry the new exception, and the service does not wrap it (InnerExceptionis null), the same asFinanceNetNoDataException.GetForexRecordsAsync, where it was retried. It now covers all methods and fails at once.GetRecordsAsyncstill callsTIME_SERIES_DAILY_ADJUSTED, for backward compatibility. On a free key it now fails at once with a clear message instead of retrying.Tests
AlphaVantageRejectedRequestTestssends the premium reply and the invalid-key reply to each of the four methods and checks that exactly one request is made. It also checks that the rate-limit reply is still retried.dotnet test --filter TestCategory=Unit: 204 passed.Adding a public exception type calls for a minor version bump in the next release.