Am Sonntag, 9. Juni 2019 16:15:38 UTC+2 schrieb Alex Miller: > > > > On Sun, Jun 9, 2019 at 8:43 AM 'Sven Richter' via Clojure < > clo...@googlegroups.com <javascript:>> wrote: > >> >> I also tried to catch the exception and *(-> ex Throwable->map >> clojure.main/ex-triage clojure.main/ex-str) *as you suggested, which >> works. But like I said, I would not want to check for exceptions during >> production that are only thrown during development. >> > > The generic question here is "what happens when my web request handler > throws an unexpected exception?" An exception can be thrown in either dev > or prod. "spec" errors are not special in this regard. Yes, you happen to > be doing some extra checking in dev, but in either case you want to > properly handle exceptions. The error handling chain above will give you > better output for all exceptions, not just spec. > > I would like to respectfully disagree here. The docs explicitly state that it is not advised to use *instrument* in production. So in production I will never see the same error messages regarding spec as in development, at least regarding to *fdef*. So what is a useful exception during development with a useful output in production it might become visible just a few functions down the stack becoming a NullpointerException, for instance. This is especially true in cases like my one, when I consume a third-party web service where the interface is prone to change.
>> Do you know of a different way? Maybe a middleware would be feasible that >> is only added during development? >> > > The question of how to handle exceptions in immutant is an immutant > question. If you read the docstring of immutant.web/run, it tells you how > to do it for ring handlers: > > For ring handlers, the actual writing of the response happens after > your hander returns. If an exception occurs on the write (the most > common case being an IOException because the client has gone away), > the default behavior is to log the exception. > > *If you would like to be able to handle that exception yourself, you can > return a function in the ring response under :write-error-handler.* > This function will > be called with the exception, the request map, and the response map > if an exception occurs when writing the response. Note that this > handler can't actually affect the response. > *If you would prefer a global handler, see > immutant.web.middleware/wrap-write-error-handling*. > I should have looked up the immutant docs myself. Unfortunately I was totally unaware of the different possible outcomes of spec errors. Anyway, thank you very much again for your explanations, I think I got it all together now and learned something new today :-) -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/9a930376-1bb8-480e-bda1-c834a9bd421e%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.