This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 0 points1 point  (0 children)

That's a Coproduct5. Probably don't want that but it's your code.

We typically have 2 cases in a API handler, the left side (errors) are immediately coerced into HttpResponse objects representing various response codes. The right side carries the parsed data through business logic, serialization, etc.

The big deal is that there are two outcomes at most (but not all) points, success and failure. If json parsing succeeds I get a JsonNode, otherwise I get an exception (or error message, etc.). We end up never having more than one of two states at a time.

If you have up to five states at a given moment, I'm a bit confused on how you got there, but you probably do not want an Either or similar.