reitit/doc/basics/error_messages.md
Joel Kaasinen f4da07c222
Some checks failed
testsuite / Clojure (Java 11) (push) Has been cancelled
testsuite / Clojure (Java 17) (push) Has been cancelled
testsuite / Clojure (Java 21) (push) Has been cancelled
testsuite / ClojureScript (push) Has been cancelled
testsuite / Lint cljdoc.edn (push) Has been cancelled
testsuite / Check cljdoc analysis (push) Has been cancelled
Release 0.9.2
2025-10-28 14:57:54 +02:00

1.6 KiB

Error Messages

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.

Default Errors

The default exception formatting uses reitit.exception/exception. It produces single-color, partly human-readable, error messages.

(require '[reitit.core :as r])

(r/router
  [["/ping"]
   ["/:user-id/orders"]
   ["/bulk/:bulk-id"]
   ["/public/*path"]
   ["/:version/status"]])

Pretty error

Pretty Errors

[metosin/reitit-dev "0.9.2"]

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 and ETA and uses fipp, expound and spell-spec for most of heavy lifting.

(require '[reitit.dev.pretty :as pretty])

(r/router
  [["/ping"]
   ["/:user-id/orders"]
   ["/bulk/:bulk-id"]
   ["/public/*path"]
   ["/:version/status"]]
  {:exception pretty/exception})

Pretty error

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 page.

Runtime Exception

See Exception Handling with Ring.