reitit/doc/basics/error_messages.md

55 lines
1.6 KiB
Markdown
Raw Normal View History

2019-05-12 18:16:01 +00:00
# Error Messages
2019-05-22 16:58:03 +00:00
All exceptions thrown in router creation are caught, formatted and rethrown by the `reitit.core/router` function. Exception formatting is done by the exception formatter defined by the `:exception` router option.
2019-05-12 18:16:01 +00:00
## Default Errors
The default exception formatting uses `reitit.exception/exception`. It produces single-color, partly human-readable, error messages.
```clj
(require '[reitit.core :as r])
(r/router
[["/ping"]
["/:user-id/orders"]
["/bulk/:bulk-id"]
["/public/*path"]
["/:version/status"]])
```
![Pretty error](../images/conflicts1.png)
## Pretty Errors
```clj
2025-10-28 12:49:37 +00:00
[metosin/reitit-dev "0.9.2"]
2019-05-12 18:16:01 +00:00
```
For human-readable and developer-friendly exception messages, there is `reitit.dev.pretty/exception` (in the `reitit-dev` module). It is inspired by the lovely errors messages of [ELM](https://elm-lang.org/blog/compiler-errors-for-humans) and [ETA](https://twitter.com/jyothsnasrin/status/1037703436043603968) and uses [fipp](https://github.com/brandonbloom/fipp), [expound](https://github.com/bhb/expound) and [spell-spec](https://github.com/bhauman/spell-spec) for most of heavy lifting.
```clj
(require '[reitit.dev.pretty :as pretty])
(r/router
[["/ping"]
["/:user-id/orders"]
["/bulk/:bulk-id"]
["/public/*path"]
["/:version/status"]]
{:exception pretty/exception})
```
![Pretty error](../images/conflicts2.png)
## Extending
Behind the scenes, both error formatters are backed by a multimethod, so they are easy to extend.
## More examples
See the [validating route data](route_data_validation.md) page.
2019-05-25 12:57:34 +00:00
## Runtime Exception
2020-12-01 09:00:20 +00:00
See [Exception Handling with Ring](../ring/exceptions.md).