Skip to content

Commit 403a8c5

Browse files
claudef3l1x
authored andcommitted
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
1 parent 7a2fafc commit 403a8c5

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.docs/errors.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Default error handler
2626

2727
- Transforms error into json response
2828
- ApiException (and inherited errors like ClientErrorException) message, context and code are used directly in response
29-
- For other (non-api) errors is used generic message described bellow
29+
- For other (non-api) errors is used generic message described below
3030
- Context is send only if is not empty
3131

3232
```json

.docs/index.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ if ($isApi) {
8080
- Console plugin
8181
- Console commands for your api.
8282
- Based on [symfony/console](https://github.com/symfony/console)
83-
- See [console](console.md) chpater for more info.
83+
- See [console](console.md) chapter for more info.
8484
- Presenter plugin
8585
- Route into your api through a single nette route and presenter.
8686
- See [presenter](presenter.md) chapter for more info.

.docs/middlewares.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,18 @@ class ExampleMiddleware implements IMiddleware
8888
}
8989
```
9090

91-
See [contributte/middlewares](https://github.com/contributte/middlewares) documentation for more info and useful middlewares
91+
See [contributte/middlewares](https://github.com/contributte/middlewares) documentation for more info and useful middlewares.
92+
93+
## Exception Handling
94+
95+
**Important note about `TryCatchMiddleware`:**
96+
97+
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.
98+
99+
Exceptions thrown during controller execution are handled internally by `ApiMiddleware`, which wraps the dispatcher call in its own try-catch block. This means:
100+
101+
- `TryCatchMiddleware` catches exceptions from middleware running before or after `ApiMiddleware`
102+
- `ApiMiddleware` catches and handles exceptions from the dispatcher (controller execution)
103+
- Controller exceptions are processed by the internal [error handler](errors.md) or [exception decorators](decorators.md#exception-decorators)
104+
105+
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)

0 commit comments

Comments
 (0)