Skip to content

fix: improve error handling when request receives non-JSON response#1477

Open
NeilSmithDLS wants to merge 6 commits intomainfrom
fix--improve-error-handling-when-request-receives-non-JSON-response
Open

fix: improve error handling when request receives non-JSON response#1477
NeilSmithDLS wants to merge 6 commits intomainfrom
fix--improve-error-handling-when-request-receives-non-JSON-response

Conversation

@NeilSmithDLS
Copy link
Copy Markdown

improve error handling when request receives non-JSON response.

Closes 1472

@NeilSmithDLS NeilSmithDLS requested a review from a team as a code owner April 9, 2026 07:45
@NeilSmithDLS NeilSmithDLS requested a review from tpoliaw April 9, 2026 07:46
@NeilSmithDLS NeilSmithDLS marked this pull request as draft April 9, 2026 10:06
@NeilSmithDLS NeilSmithDLS marked this pull request as draft April 9, 2026 10:06
@codecov
Copy link
Copy Markdown

codecov bot commented Apr 9, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 95.22%. Comparing base (65b7e75) to head (4563955).

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1477      +/-   ##
==========================================
+ Coverage   95.21%   95.22%   +0.01%     
==========================================
  Files          43       43              
  Lines        3132     3141       +9     
==========================================
+ Hits         2982     2991       +9     
  Misses        150      150              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@NeilSmithDLS NeilSmithDLS force-pushed the fix--improve-error-handling-when-request-receives-non-JSON-response branch from 566bd02 to ba9a28b Compare April 9, 2026 13:29
@NeilSmithDLS NeilSmithDLS marked this pull request as ready for review April 10, 2026 11:04
Comment on lines 109 to 119
code = response.status_code
if response.content:
try:
response.json()
except json.decoder.JSONDecodeError:
return BlueskyRemoteControlError(
"Response does not contain a valid JSON object"
)
if code < 400:
return None
elif code == 404:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would happen if you got a 500 code, that held html?

Copy link
Copy Markdown
Contributor

@tpoliaw tpoliaw left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure the _exception method is the best place for this check to be, for instance running a plan uses the alternative _create_task_exceptions method and bypasses this check

$ # with config pointing to oauth-proxy
$ uv run blueapi -c path/to/config.yaml controller run --bg -i cm12345-3 sleep '{"time": 3}'
Error: task could not run: Expecting value: line 1 column 1 (char 0)

We're also parsing the json multiple times on the happy path when everything is working which isn't ideal.

Would it work to add a helper method to wrap wherever we're calling .json()?

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.

BlueapiClient gives unhelpful error message when invalid JSON is returned

3 participants