Better Exception docs

This commit is contained in:
Tommi Reiman 2018-10-31 19:25:21 +02:00
parent d24f86ccfe
commit 2c58205e85
2 changed files with 13 additions and 5 deletions

View file

@ -54,12 +54,16 @@ A preconfigured middleware using `exception/default-handlers`. Catches:
Creates the exception-middleware with custom options. Takes a map of `identifier => exception request => response` that is used to select the exception handler for the thown/raised exception identifier. Exception idenfier is either a `Keyword` or a Exception Class.
The following handlers special keys are available:
The following handlers are available by default:
| key | description
|------------------------|-------------
| `::exception/default` | a default exception handler if nothing else mathced (default `exception/default-handler`).
| `::exception/wrap` | a 3-arity handler to wrap the actual handler `handler exception request => response` (no default).
| key | description
|--------------------------------------|-------------
| `:reitit.ring/response` | value in ex-data key `:response` will be returned
| `:muuntaja/decode` | handle Muuntaja decoding exceptions
| `:reitit.coercion/request-coercion` | request coercion errors (http 400 response)
| `:reitit.coercion/response-coercion` | response coercion errors (http 500 response)
| `::exception/default` | a default exception handler if nothing else mathced (default `exception/default-handler`).
| `::exception/wrap` | a 3-arity handler to wrap the actual handler `handler exception request => response` (no default).
The handler is selected from the options map by exception idenfitifier in the following lookup order:

View file

@ -28,6 +28,7 @@ Setting the `redirect-trailing-slash-handler` as a second argument to `ring-hand
(app {:uri "/ping/"})
; {:status 308, :headers {"Location" "/ping"}, :body ""}
(app {:uri "/pong"})
; {:status 308, :headers {"Location" "/pong/"}, :body ""}
```
@ -45,9 +46,11 @@ Setting the `redirect-trailing-slash-handler` as a second argument to `ring-hand
(app {:uri "/ping/"})
; {:status 308, :headers {"Location" "/ping"}, :body ""}
(app {:uri "/pong"})
; nil
```
```clj
(def app
(ring/ring-handler
@ -59,6 +62,7 @@ Setting the `redirect-trailing-slash-handler` as a second argument to `ring-hand
(app {:uri "/ping/"})
; nil
(app {:uri "/pong"})
; {:status 308, :headers {"Location" "/pong/"}, :body ""}
```