Hi All,
I was going through
Stack Exchange - Why should 'boneheaded' exceptions not be caught, especially in server code?(in my case it will not cause server crash)
and it reminded me few scenario which I faced some time back and looking for what should be correct solution/feedback.
I will try to explain scenario and my understanding.
1. GET /uri/<storeId>/orders, This api will return list of store orders(array of JSON object). Internal logic of API is like that it will collect stores order ids from different source(step 1) and start collecting details(step 2) for each order and while collecting order detail for any order it may get exception(may be order got corrupted by some process) it will cause whole API to fail and API will return respective error so that store(client) can inform back to us and we should investigate the issue and fix it. But investigation can take time so we created a flag which will change API behavior and force it log the exception for corrupted order and return rest of orders.
If flag is true then PROS of this approach is that store will able to keep processing order(consider 10 order a day) but we have rely on someone who monitor logs and if missed we will never notice that something wrong happening with some orders.
If flag is OFF, API will fail and return error and we have to rely on stores exception handling(whether they inform us back or not) + someone from team to monitor logs. If none notice the issue those order will never get processed.
Query - Should we go with flag value as true/false ?
2. User object is injected by framework in our code. We can get user attributes by its getProperty method, eg. user.getProperty("firstName"). I have seen people put a NPE check before getting any value form user object with explanation that it will not cause any issue(which is correct). But as my understanding if user is null then something is already wrong with application and we should not put NPE as we will never know that it happened(Obviously customer will never get "firstName" if user is null).
Query - Shouldn't we avoid these checks ?