From d2ac64134d5d7afe66c8d53f9cf1370f341e4af8 Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 5 Dec 2025 12:00:31 +0000 Subject: [PATCH] Update docs: clarify TryCatchMiddleware behavior and fix typos - Add Exception Handling section to middlewares.md explaining that TryCatchMiddleware only catches exceptions in middleware, not in controllers (fixes #173) - Fix typo: "chpater" -> "chapter" in index.md - Fix typo: "bellow" -> "below" in errors.md --- .docs/errors.md | 2 +- .docs/index.md | 2 +- .docs/middlewares.md | 16 +++++++++++++++- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/.docs/errors.md b/.docs/errors.md index bdf5e5af..ae2bc957 100644 --- a/.docs/errors.md +++ b/.docs/errors.md @@ -26,7 +26,7 @@ Default error handler - Transforms error into json response - ApiException (and inherited errors like ClientErrorException) message, context and code are used directly in response - - For other (non-api) errors is used generic message described bellow + - For other (non-api) errors is used generic message described below - Context is send only if is not empty ```json diff --git a/.docs/index.md b/.docs/index.md index bf7a34db..c50e8c64 100644 --- a/.docs/index.md +++ b/.docs/index.md @@ -80,7 +80,7 @@ if ($isApi) { - Console plugin - Console commands for your api. - Based on [symfony/console](https://github.com/symfony/console) - - See [console](console.md) chpater for more info. + - See [console](console.md) chapter for more info. - Presenter plugin - Route into your api through a single nette route and presenter. - See [presenter](presenter.md) chapter for more info. diff --git a/.docs/middlewares.md b/.docs/middlewares.md index 52b25813..049d3744 100644 --- a/.docs/middlewares.md +++ b/.docs/middlewares.md @@ -88,4 +88,18 @@ class ExampleMiddleware implements IMiddleware } ``` -See [contributte/middlewares](https://github.com/contributte/middlewares) documentation for more info and useful middlewares +See [contributte/middlewares](https://github.com/contributte/middlewares) documentation for more info and useful middlewares. + +## Exception Handling + +**Important note about `TryCatchMiddleware`:** + +If you use `TryCatchMiddleware` from [contributte/middlewares](https://github.com/contributte/middlewares), be aware that it only catches exceptions thrown in **other middleware**, not exceptions thrown in controllers. + +Exceptions thrown during controller execution are handled internally by `ApiMiddleware`, which wraps the dispatcher call in its own try-catch block. This means: + +- `TryCatchMiddleware` catches exceptions from middleware running before or after `ApiMiddleware` +- `ApiMiddleware` catches and handles exceptions from the dispatcher (controller execution) +- Controller exceptions are processed by the internal [error handler](errors.md) or [exception decorators](decorators.md#exception-decorators) + +If you need custom exception handling for controller errors, use [exception decorators](decorators.md#exception-decorators) or implement a custom [error handler](errors.md#error-handler)