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. 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 | key | description
|------------------------|------------- |--------------------------------------|-------------
| `::exception/default` | a default exception handler if nothing else mathced (default `exception/default-handler`). | `:reitit.ring/response` | value in ex-data key `:response` will be returned
| `::exception/wrap` | a 3-arity handler to wrap the actual handler `handler exception request => response` (no default). | `: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: 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/"}) (app {:uri "/ping/"})
; {:status 308, :headers {"Location" "/ping"}, :body ""} ; {:status 308, :headers {"Location" "/ping"}, :body ""}
(app {:uri "/pong"}) (app {:uri "/pong"})
; {:status 308, :headers {"Location" "/pong/"}, :body ""} ; {: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/"}) (app {:uri "/ping/"})
; {:status 308, :headers {"Location" "/ping"}, :body ""} ; {:status 308, :headers {"Location" "/ping"}, :body ""}
(app {:uri "/pong"}) (app {:uri "/pong"})
; nil ; nil
``` ```
```clj ```clj
(def app (def app
(ring/ring-handler (ring/ring-handler
@ -59,6 +62,7 @@ Setting the `redirect-trailing-slash-handler` as a second argument to `ring-hand
(app {:uri "/ping/"}) (app {:uri "/ping/"})
; nil ; nil
(app {:uri "/pong"}) (app {:uri "/pong"})
; {:status 308, :headers {"Location" "/pong/"}, :body ""} ; {:status 308, :headers {"Location" "/pong/"}, :body ""}
``` ```