1 points · by gkrishna · 3y ago · 0 comments
We are trying to establish a error handling framework.
My peer came up with this simple POC. The idea is that this function will reduce amount of try catch used in the business logic.
---
function errorHandler(func, ...params) { try { return func(params) } catch (e) { console.log('error on function ${func}`) throw e; } }
errorHandler(fetch, 'api url') ---
But I think it is not a good idea to have a generic handler like this and it is ok to have try catch for each function.
My question- is the above handler is ok or is there any better way to handle errors? Your input is greatly appreciated.
No comments yet.