For our REST APIs, we have middleware that catches exceptions, logs them, and returns an error response to the caller.
If we have a specific handler that can fail in an expected way, we write that into the logic and respond to the caller with an error response – much like the middleware does. With just a small tweak on how the middleware works, we could easily replace the handler error logic with throw of ex-info (with appropriate data) and probably simplify our code. Which is to say: I agree with Alex that exceptions are the idiomatic way to go in Clojure and ex-info / ex-data (and now ex-message and ex-cause) provide all the hooks you need for conveying error information along with those exceptions. Sean Corfield -- (970) FOR-SEAN -- (904) 302-SEAN An Architect's View -- http://corfield.org/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ________________________________ From: clojure@googlegroups.com <clojure@googlegroups.com> on behalf of Didier <didi...@gmail.com> Sent: Thursday, October 25, 2018 11:32:12 PM To: Clojure Subject: Re: An Error spec? Interesting. I understand that, I guess it's because of my usage of spec. I tend to use spec exclusively at the boundaries. Think serialization. Sometimes, I have a producer which can't handle the error, so it must be serialized and exchanged to the consumer. So say the producer couldn't produce the value, for some reason. In some cases, that's a bug, and I throw an exception, and fail the producer itself. But sometimes, its an expected possibility, in which case, tbe value is an error. And the producer must communicate that out. Unfortunatly, exceptions are not friendly to serialization or spec. So I need to roll my own error structure, serialize that, and spec it. -- 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. For more options, visit https://groups.google.com/d/optout. -- 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. For more options, visit https://groups.google.com/d/optout.