1. There are status handlers for 404 and 500 setup by default. To
create your own custom status page, use:
(noir.statuses/set-page! code content)
before starting the server.
2. As for getting the exception, Noir includes a middleware function
called wrap-exceptions that will print the stack trace if in :dev
mode, and will return the 500 status page if not. To actually get the
exception and do stuff with it yourself, you would probably want to
write a similar middleware that will store the exception somewhere you
can get to it (in a dynamic thread-local var, for example).
- Mark
Actually, it might make more sense if Noir bound the exception in
wrap-exceptions to something like, for example, noir.exception/*excp*.
Is this something that would be considered?
How about setting custom headers? Does that have to be done in a middleware handler, too? I have some specialized tasks outside the normal web-app stuff for which I'd like to add some headers on the response, but don't see how to do that.
Even returning {:status 200 :headers {:test "Test"}} gets me a "Key must be integer" error, which is completely opaque to me at this point.
I realize that such things are a little bit low level, but I just need it for this one part..... ;)
Keith
You can redirect to another page from the pre-route. That should work
for most situations.
(require '[noir.response :as response]
...
(pre-route "/some/path" {}
(if some-condition
(response/redirect "/some/other/path")))
Yeah, I completely missed that fact. I was thinking things like
custom logging and alerts, etc. How would you handle things like
those? I assume by writing your own version of wrap-exceptions, but
then wouldn't be able to use noir.server.handler/wrap-noir-middleware,
correct (so you would need to add the rest of those middlewares
yourself)? I'm wondering if there is a more straightforward way one
could specify a custom exception handler.
- Mark