Skip to content

call .raise_for_status() before .json() for certain requests - #15236

Open
talflon wants to merge 1 commit into
Charcoal-SE:masterfrom
talflon:dg-raise-for-status-json
Open

call .raise_for_status() before .json() for certain requests#15236
talflon wants to merge 1 commit into
Charcoal-SE:masterfrom
talflon:dg-raise-for-status-json

Conversation

@talflon

@talflon talflon commented May 22, 2026

Copy link
Copy Markdown

Addresses #15227. .json() on Metasmoke requests was causing an error like

requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

so this calls raise_for_status() first, which will raise an HTTPError instead if it's a 4xx or 5xx HTTP error.

I also did this in chatcommands.pull(), because that method appears to assume a successful response.

I didn't do this for:

  • the other GitHub API requests: seems we might rely on parsing the JSON body of an error response
  • StackExchange API requests: seems we might rely on parsing the JSON body of an error response
  • the ChatExchange call in chatcommunicate.sendmessages(): seems there is some error handling in ChatExchange
  • findspam.toxic_check(): looks as if errors are returned as JSON
  • Metasmoke.get() itself: MetasmokeCache.fetch_from_api() calls .get() and then handles the status code separately
  • BodyFetcher.make_api_call_for_site(): all exceptions are swallowed, so makes no difference
  • deletionwatcher._check_batch(): this code appears to have been obsolete for over a year

- mostly for Metasmoke requests, because those often return empty responses
- only where we depend on a successful JSON response
- addresses Charcoal-SE#15227
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant