Pedestal 0.4.0 includes io.pedestal.interceptor.error/error-dispatch
, which uses core.match
to make error handling very tidy. For example
creates an error handler that tries to matches any Throwable
from ,
The error-dispatch
macro splices its forms after the binding vector ([context ex]
above) into a core.match
expression matching against the ex-data
of our exception, which is defined in io.pedestal.impl.interceptor
, and contains :execution-id
, :stage
, :interceptor
, :exception-type
, and :exception
.
So my-error-handler
will respond with a 400
for any Throwable
from the interceptor named :io.pedestal.http.body-params/body-param
, etc.
Giving a nice separation between the semantically-correct error for an interceptor to throw (e.g. a parser error for invalid JSON) and the response that’s generated (a status 400 for invalid input).