refactor(server): make a refusal its own HTTP response - #118
Merged
Conversation
`MediaResolutionError` and `SidecarError` subclassed plain `Exception` and carried a status and detail that something else had to convert: two converter functions, and a catch-and-re-raise at all six call sites that did nothing but copy two fields into an `HTTPException`. Subclassing `HTTPException` instead makes the refusal the response. Raised from anywhere under a route, FastAPI renders it with the status and detail the raising module chose, so both converters and every rewrap go. 52 deletions, 30 insertions; 2,708 -> 2,679 code lines. They stay two types rather than collapsing into one shared refusal, because `_media.is_uri_servable` catches media refusals specifically -- a single shared type would let it swallow an unrelated refusal raised nearby. Behaviour is unchanged and checked rather than assumed: the OpenAPI schema dumps byte-identical before and after, and every status assertion in the media, sidecar and pin suites still passes (645 tests). Found by an audit of whether this package earns its lines. Its verdict was mostly no-change -- roughly 1% of the code was signed off as safely deletable, and the file count was explicitly not the problem. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
MediaResolutionErrorandSidecarErrorsubclassed plainExceptionand carried a status and detail that something else had to convert into anHTTPException— two converter functions, plus a catch-and-re-raise at all six call sites that did nothing but copy two fields.Subclassing
HTTPExceptioninstead makes the refusal be the response. Raised from anywhere under a route, FastAPI renders it with the status and detail the raising module chose, so both converters and every rewrap go.52 deletions, 30 insertions — 2,708 → 2,679 code lines.
They stay two types rather than collapsing into one shared refusal, because
_media.is_uri_servablecatches media refusals specifically; a single shared type would let it swallow an unrelated refusal raised nearby.Verification
Behaviour is unchanged and checked rather than assumed:
ruffandtyclean.Provenance
This came out of an audit asking whether
hflow-serverearns its lines, after the question "why do we need so many files for the server". The honest answer was mostly that it does: across three independent deletion theses, each adversarially attacked with claims re-verified on a clean copy, ~1% of the code was signed off as safely deletable, and the file count was explicitly not the problem. This is that 1%.Two of the rejected items are worth recording, since both reviewers that proposed them had them wrong: the claim that these classes already subclassed
HTTPException(they did not — hence the__init__s were load-bearing), and a claim that a committed React bundle sat in the wheel (a real bug at the time, fixed separately in #116 before this ran).🤖 Generated with Claude Code