reitit/doc/basics/error_messages.md
Joel Kaasinen 373ea9bb62
Some checks are pending
testsuite / Clojure 11 (Java 11) (push) Waiting to run
testsuite / Clojure 11 (Java 17) (push) Waiting to run
testsuite / Clojure 11 (Java 21) (push) Waiting to run
testsuite / Clojure 11 (Java 25) (push) Waiting to run
testsuite / Clojure 12 (Java 11) (push) Waiting to run
testsuite / Clojure 12 (Java 17) (push) Waiting to run
testsuite / Clojure 12 (Java 21) (push) Waiting to run
testsuite / Clojure 12 (Java 25) (push) Waiting to run
testsuite / ClojureScript (push) Waiting to run
testsuite / Lint cljdoc.edn (push) Waiting to run
testsuite / Check cljdoc analysis (push) Waiting to run
Release 0.10.0
2026-01-09 10:07:15 +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.10.0"]

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.