Settings

Theme

Ask HN: What is the best approach for TypeScript error handler?

1 points by gkrishna 3 years ago · 0 comments · 1 min read


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.

No comments yet.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection