Fix misleading "Invalid credentials" error when requested data is not available#660
Open
AlexCatarino wants to merge 2 commits into
Open
Conversation
When `lean data download` requests a data path that is not available, the data/list API endpoint responds with a 500 status code and an empty body, which the API client translates into an AuthenticationError with the message "Invalid credentials, please log in using `lean login`". This is misleading since the credentials are valid: earlier requests in the download flow (data/prices, organization lookups) have already succeeded by the time data/list is called. Catch the error in DataClient.list_files and raise a clear message telling the user the requested data is not available and to contact support@quantconnect.com. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Attach the response to AuthenticationError when it is inferred from an HTTP 500 status code, so DataClient.list_files can distinguish the "data not available" case from genuinely invalid credentials (hash mismatch) and only replace the message for the former. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Description
When
lean data downloadrequests a data path that is not available, e.g.:the
data/listAPI endpoint responds with status code 500 and an empty body:The API client maps any 500 response to an
AuthenticationError, so the user seesInvalid credentials, please log in using 'lean login'— misleading, since the credentials are valid (earlier authenticated requests in the download flow such asdata/priceshave already succeeded by the timedata/listis called).This PR catches that error in
DataClient.list_filesand raises a clear message instead:The response is now attached to
AuthenticationErrorwhen it is inferred from a 500 status code, solist_filesonly replaces the message in that case — anAuthenticationErrorcaused by genuinely invalid credentials (hash mismatch) is re-raised unchanged. Other failures are untouched:success: falseresponses keep the API's own error text, and other status codes keep the generic request-failed message.Testing
Simulated all
data/listfailure modes through the realAPIClient/DataClientwith a mocked HTTP layer:The requested data with prefix '...' is not available, please contact support@quantconnect.comInvalid credentials, please log in using 'lean login'(unchanged)success: falsewith API error textDirectory not found: ...(unchanged)POST request to .../data/list failed with status code ...(unchanged)Added unit tests covering the first two rows. No open issues were found tracking this.
🤖 Generated with Claude Code