|
|
|
Ask HN: What is the best approach for TypeScript error handler?
|
|
1 points
by gkrishna
1280 days ago
|
|
Hey all, I would like to know your thoughts on our internal discussion. 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. |
|