Export error classes from @hackmd/api

未關閉 適合新手
#73 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
74/100
Issue 類型
功能
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
node.js, typescript
領域
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 摘要。