Skip to content

Fix: Improve message when submit() receives a non-JSON response#137

Open
flamingbear wants to merge 5 commits into
mainfrom
fix/improve-submit-json-error-message
Open

Fix: Improve message when submit() receives a non-JSON response#137
flamingbear wants to merge 5 commits into
mainfrom
fix/improve-submit-json-error-message

Conversation

@flamingbear
Copy link
Copy Markdown
Member

@flamingbear flamingbear commented Jun 4, 2026

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:

Identifies the likely cause (authentication failure) 
Tells the user to check their .netrc file for the Earthdata Login host
Includes the raw response status code and first 200 characters for further debugging

Before:

JSONDecodeError: Expecting value: line 1 column 1 (char 0)

After:

If the non-JSON respose doesn't have the words "Earthdata Login", we just return a short message

Harmony returned a non-JSON response. [200 characters of the response]

If the response looks like a login page, via has the words "Earthdata Login" on it.

Exception: Harmony returned a non-JSON response. This may indicate an
authentication failure. Check that your .netrc file contains valid
credentials for the Earthdata Login host (e.g.
urs.earthdata.nasa.gov or uat.urs.earthdata.nasa.gov).
Raw response (200): <!DOCTYPE html>...

someshnagalla and others added 3 commits June 1, 2026 11:19
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.
@flamingbear flamingbear changed the title Fix/improve submit json error message Fix: improve message when submit() receives a non-JSON response Jun 4, 2026
@flamingbear flamingbear changed the title Fix: improve message when submit() receives a non-JSON response Fix: Improve message when submit() receives a non-JSON response Jun 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve error message when harmony_client submission fails

2 participants