How do I get a return value from catch to be sent as a response via Ring and Jetty?

Let’s assume I’ve a simple Web setup and I’m using Ring and Jetty close to their defaults. I have a handler that I give to Jetty. My understanding is that whatever is return from the handler should be sent by Jetty to client who made the Web request. I have also read that the final value in a Catch block is the value that will return.

Divide by zero to create an exception. I’m expecting to see the last form in the Catch block. And yet this does not work:

(defn handler [request]
  (try
    (/ 1 0)
    (catch Exception e
      (log/log e)
      {:message "Error: our engineers are working to fix this."})
    (finally
      {:message "Error: our engineers are working to fix this."})))

If I run this locally, and I open Terminal, and I ping localhost:7001, which is the port I have this running on, then I get no response.

What do I need to do to return the value from the Catch or the Finally, when there is an Exception?

Note that it doesn’t mean whatever finally returns. Instead, it means the last expression in the catch form. The value returned by finally can never be used.

Can’t say for certain without seeing the rest of the code, but unless you have some middleware that turns arbitrary maps into proper responses, your handler does not actually return a proper response. A Ring response, according to the Ring’s spec, is a map with at least the following keys: :body, :headers, :status.

Okay, thanks. I’ve made the same mistake a dozen times now. I need to rearrange this so everything goes through the call to ring/response.