-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(misskey-js): エラーを型として出力・利用できるように #14069
base: develop
Are you sure you want to change the base?
feat(misskey-js): エラーを型として出力・利用できるように #14069
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## develop #14069 +/- ##
============================================
- Coverage 77.90% 65.25% -12.66%
============================================
Files 185 1004 +819
Lines 25563 115306 +89743
Branches 487 5541 +5054
============================================
+ Hits 19916 75246 +55330
- Misses 5640 38621 +32981
- Partials 7 1439 +1432 ☔ View full report in Codecov by Sentry. |
misskey/packages/misskey-js/src/api.ts Lines 52 to 56 in 2acbec6
Pがジェネリクスなのでそうなる |
どう直せば型補完がちゃんと効くようになるかしら・・・ |
Ideaであれば補完自体は出てきたと思うけどVSCだとだめなのか |
code側の問題? |
codeのアプデ来てたのでちょっと試してみます |
だめだった |
モノ自体はなにもおかしくないしエラーハンドリングはちゃんと型定義通っているのでマージしても大丈夫そう |
…kokari-gtyih/misskey into feat-mijs-expose-error-types
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ErrPromise<T,RE>
という方針、fetch
の各種エラー(fetch がネットワークエラーを発生した場合のTypeErrorとか)がMisskey.Endpoints[E]['errors']
に化けちゃってすごく良くない気がします。
そのとおりだけど良い直し方が思いつかない… |
nominal type idiomで各エラーを包んだらいい感じにそのふるまいをオプトアウト出来そう |
私はそもそも元の実装からそうですがJsonのオブジェクトをそのままthrow(reject)するのが悪手だと思ってます。 ApiError的なErrorを継承したclassのインスタンスにしてthrowするようにし、これのエラーペイロードに関して |
大規模にコードを修正しないといけない割には使用箇所が限られるので今やる必要はないかも |
これについてはCONTRIBUTING.mdで禁止したあとno-throw-literalをerrorにして違反箇所を随時潰していくしかないと思っている |
} | ||
|
||
export function isAPIError<ER extends Endpoints[keyof Endpoints]['errors']>(reason: any): reason is APIError<ER> { | ||
return reason instanceof Error && MK_API_ERROR in reason; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instanceof
は公称型のチェックになるのでreason instanceof APIError
にしてMK_API_ERROR
symbolはなくしていい気がする。
What
os.apiWithDialog
で、エラーコードごとにカスタムエラーメッセージを指定できるようにmisskeyApi
のreject側の戻り値にエラー型が出るようにWhy
Additional info (optional)
独自エラーの追加はこんな感じ
Checklist