Re:You’re better off using Exceptions
by barrkel on Monday February 03, 2020 @12:10PM
(#22226206)
Of course, if you're in a web app, and you've received an email address, and you can't find a User record for that email address, a perfectly valid approach would be for the fetch to throw a 'not found' exception and to generically handle all 'not found' exceptions in request handlers to return 404 status codes.
[ Parent
| on HN ]
Then would you be nesting a number of exceptions. Some maybe real 404 exceptions, but some would be zero records found. And I think the zero records found should be handled in the business logic (if statements, switch/case), not in the exceptions.
The expectation of a single result should be encoded in the API, not the business logic. It's a very common expectation for e.g. identifiers found on http paths.
Re:You’re better off using Exceptions
by joshuamorton on Monday February 03, 2020 @02:06PM
(#22227699)
If I expect exactly one result, zero results is exceptional. If I expect zero or more results, zero results should be handled by the business logic.