TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

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

1 点作者 gkrishna超过 2 年前
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.

暂无评论

暂无评论