TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

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

1 pointsby gkrishnaover 2 years ago
Hey all, I would like to know your thoughts on our internal discussion.<p>We are trying to establish a error handling framework.<p>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.<p>---<p>function errorHandler(func, ...params) { try { return func(params) } catch (e) { console.log(&#x27;error on function ${func}`) throw e; } }<p>errorHandler(fetch, &#x27;api url&#x27;) ---<p>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.<p>My question- is the above handler is ok or is there any better way to handle errors? Your input is greatly appreciated.

no comments

no comments