Skip to content

Improve error handling: stop swallowing errors and propagate proper HTTP status codes - #1

Open
devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783577429-error-handling
Open

devin-ai-integration[bot] wants to merge 1 commit into
mainfrom
devin/1783577429-error-handling

Conversation

@devin-ai-integration

Copy link
Copy Markdown

Summary

Fixes several places in main.py where errors were silently swallowed or surfaced as unhelpful 500s.

Relay tasks no longer swallow errors. tcp_to_ws previously had a blanket except Exception: pass, and unexpected exceptions in ws_to_tcp escaped into a task that was never awaited (dropped + "Task exception was never retrieved" warnings). Both now distinguish expected teardown from real failures:

except asyncio.CancelledError: raise          # keep cancellation working
except WebSocketDisconnect: pass              # normal client close
except (ConnectionError, RuntimeError): log.debug(...)   # socket torn down mid-relay
except Exception as exc: record_error(exc, ...); log.error(...)

websocket_tunnel surfaces task failures. After asyncio.wait(..., FIRST_COMPLETED) it now gathers the cancelled pending tasks (clean teardown) and re-raises any exception from the finished task instead of dropping it. The outer handler routes through the new record_error(...) helper (increments stats["total_errors"] + appends to error_logs).

Malformed request bodies return 400, not 500. Added parse_json_body() (rejects non-JSON / non-object bodies) and _to_float() (rejects non-numeric limit_value), wired into api_login, api_change_password, create_link, and toggle_link. Previously await request.json() / float(...) on bad input raised unhandled → 500.

http_proxy differentiates failures. Guards http_client is None (503), maps httpx.TimeoutException504, httpx.HTTPError502, and logs/records all via record_error.

Verification

Ran the app locally and exercised the paths: invalid-JSON and array bodies → 400, wrong password → 401, valid login → 200, non-numeric limit_value400, valid link creation → 200. python -m py_compile passes; the only pyflakes warnings are pre-existing unused imports untouched by this change.

Link to Devin session: https://app.devin.ai/sessions/aecaede8a13e4e1e990020243c687dc7
Requested by: @hmilan1366

…TTP status

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@hmilan1366 hmilan1366 self-assigned this Jul 9, 2026
@devin-ai-integration

Copy link
Copy Markdown
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment, CI, and merge conflict monitoring

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.

2 participants