Export error classes from @hackmd/api

未关闭 适合新手
#73 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
74/100
Issue 类型
功能
描述清晰度
描述清楚
活跃度
活跃
领域
api

调研方向

先阅读 nodejs/src/error.ts、包根目录的导出内容和 CommonJS 构建配置,了解公共导出是如何组装的。将错误类添加到两个包入口点,并在 README 中添加一个简短的“处理错误”示例。完成标准是:使用者能够在两种构建中从 @hackmd/api 导入这些类,并且 README 展示如何检查错误类型并访问其详细信息。

由索引模型根据 Issue 内容生成。

描述

Problem

@hackmd/api throws its own error classes, such as HttpResponseError, TooManyRequestsError and InternalServerError (defined in nodejs/src/error.ts), but the package does not export them. Users cannot check the error type:

import { API, TooManyRequestsError } from '@hackmd/api' // not exported

try {
  await client.getNote(noteId)
} catch (error) {
  if (error instanceof TooManyRequestsError) {
    // wait error.resetAfter, then try again
  }
}

Today they can only read (error as Error).message, so details such as the HTTP status code or the rate-limit fields userRemaining and resetAfter are hard to reach.

Proposal

Export the error classes from the package root (and the CommonJS build), and add a short "Handle errors" example to the README.

主要语言
TypeScript
星标
20
派生
8
平均合并
47 分钟
30 天内合并 PR
5

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

hackmdio/api-client 的其他 Issue

查看 hackmdio/api-client 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。