Fix: Improve message when submit() receives a non-JSON response#137
Open
flamingbear wants to merge 5 commits into
Open
Fix: Improve message when submit() receives a non-JSON response#137flamingbear wants to merge 5 commits into
flamingbear wants to merge 5 commits into
Conversation
When Harmony returned a non-JSON body (typically an HTML redirect from the Earthdata Login page due to missing or invalid .netrc credentials), the OgcBaseRequest code path raised a bare JSONDecodeError with no actionable information. Wrap response.json() in a try/except for the OgcBaseRequest path and raise a descriptive Exception that tells the user to check their .netrc credentials for the Earthdata Login host. Fixes #129
Before telling the user it's a login problem make sure the response has "earthdata login" in it. Otherwise just say it's non-JSON.
Non login response.
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.
Pulling in user contribution: #130
Fixes #129.
Problem
When harmony_client.submit() is called but authentication is missing or broken, Harmony redirects the request to the Earthdata Login page — returning HTML instead of JSON. The OgcBaseRequest code path called response.json() without a try/except, so users saw a raw JSONDecodeError: Expecting value: line 1 column 1 with no indication of what actually went wrong.
Fix
Wrap response.json() in a try/except requests.exceptions.JSONDecodeError for the OgcBaseRequest path and raise a descriptive Exception that:
Before:
After:
If the non-JSON respose doesn't have the words "Earthdata Login", we just return a short message
If the response looks like a login page, via has the words "Earthdata Login" on it.