Skip to content

fix(server): return ErrorResponse for framework-raised HTTP errors - #3117

Merged
Pangjiping merged 1 commit into
opensandbox-group:mainfrom
kongxinjun:fix/error-response-framework-errors
Nov 26, 2026
Merged

Pangjiping merged 1 commit into
opensandbox-group:mainfrom
kongxinjun:fix/error-response-framework-errors

Conversation

@kongxinjun

Copy link
Copy Markdown
Contributor

Summary

  • sandbox_http_exception_handler is registered for fastapi.exceptions.HTTPException, which subclasses Starlette's HTTPException. Errors the framework raises with the Starlette class skip it and keep Starlette's default body:

    request status body before body after
    GET /v1/no-such-route 404 {"detail":"Not Found"} {"code":"GENERAL::UNKNOWN_ERROR","message":"Not Found"}
    PUT /v1/sandboxes 405 {"detail":"Method Not Allowed"} {"code":"GENERAL::UNKNOWN_ERROR","message":"Method Not Allowed"}
    PATCH /v1/sandboxes/{id}/networkpolicy with a non-UTF-8 body 400 {"detail":"There was an error parsing the body"} {"code":"GENERAL::UNKNOWN_ERROR","message":"There was an error parsing the body"}

    The lifecycle spec declares ErrorResponse (code and message required, no other properties) for every non-2xx response, and the SDKs parse that shape. Registering the handler on Starlette's base class covers both. Status codes and headers (e.g. Allow on 405) are unchanged; FastAPI's own HTTPException is still handled the same way.

  • Request-validation errors (422) are not touched.

Testing

  • Not run (explain why)

  • Unit tests

  • Integration tests

  • e2e / manual verification

  • tests/test_routes.py::TestFrameworkErrorResponses (unknown route, 405, unparseable body): 3 fail on main, pass with the change.

  • uv run pytest: 3197 passed, 34 skipped. uv run ruff check: clean.

  • Found by running schemathesis against the lifecycle spec on a local Docker-runtime server.

Breaking Changes

  • None
  • Yes (describe impact and migration path)

Clients that read detail from a 404/405 body now get code/message, which is what the spec documents.

Checklist

  • Linked Issue or clearly described motivation
  • Added/updated docs (if needed)
  • Added/updated tests (if needed)
  • Security impact considered
  • Backward compatibility considered

The error handler was registered for FastAPI's HTTPException, a subclass
of Starlette's. Errors the framework raises with the Starlette class (unknown
route 404, 405, unparseable body 400) bypassed it and returned
{"detail": ...} instead of the {code, message} ErrorResponse the spec
declares for every non-2xx response. Register the handler on the base class.

Signed-off-by: kongxin <kongxin326@gmail.com>
@github-actions github-actions Bot added component/server size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Nov 26, 2026
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-26T01:36:51.157994Z 2f3921d PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@Pangjiping Pangjiping left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM

@Pangjiping
Pangjiping merged commit 87bf1ff into opensandbox-group:main Nov 26, 2026
63 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component/server size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants