Skip to content

feat(web)!: derive exception handlers from the application's definitions - #344

Open
mofr wants to merge 1 commit into
feat/applicationfrom
feat/exception-handlers
Open

mofr wants to merge 1 commit into
feat/applicationfrom
feat/exception-handlers

Conversation

@mofr

@mofr mofr commented Oct 25, 2026

Copy link
Copy Markdown
Collaborator

Stacked on #343; retargets to v34 once #343 merges.

An exception handler is a method marked with @winter.web.exception_handler. Its first argument is annotated with the exceptions it handles (a union for several):

class FileStorageExceptionHandlers:
    @winter.web.exception_handler
    @winter.web.response_status(HTTPStatus.BAD_GATEWAY)
    def handle_download(self, exception: FileStorageDownloadException) -> ErrorDTO:
        ...
  • create_urls(app) and generate_openapi(app) collect the handlers of the application from app.definitions (handler methods and @problem exceptions), over the built-in handlers of winter.web (500 for Exception, redirect, Winter's own problems). A handler of the application replaces the built-in one of the same exception class; then the handler of the nearest class in the exception's MRO handles it.
  • Two handlers of one exception class in an application, or a handler whose first argument is not annotated with exceptions, fail on startup.
  • Every handler handles its exceptions in all endpoints of its application. @raises(Exc) only declares the response for OpenAPI.
  • Removed: ExceptionHandler, exception_handlers_registry (add_handler, set_default_handler), the handler argument of @raises.
  • The isolation test tests/test_application_scope.py passes; xfail is removed.
  • OpenAPI: @raises(X) for an exception without a handler now documents the built-in 500 response; before, the default handler's response overwrote the success response.

🤖 Generated with Claude Code

An exception handler is a method marked with @winter.web.exception_handler; its first argument is
annotated with the exceptions it handles. Adapters collect the handlers of an application from its
definitions, over the built-in ones of winter.web, so two applications in one process no longer share
them and the isolation test passes.

BREAKING CHANGE: ExceptionHandler, exception_handlers_registry (add_handler, set_default_handler) and
the handler argument of @raises are removed. Every handler handles its exceptions in all endpoints of
its application, by the nearest class in the exception's MRO; a handler of Exception replaces the
default 500 response.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
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.

1 participant