Skip to content
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

fix: 通知からロール参照時にロールが存在しないときの例外処理を追加 #14500

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

hinanoaira
Copy link

@hinanoaira hinanoaira commented Sep 5, 2024

What

このプルリクエストでは、通知に含まれるロールが削除されている場合に発生する例外を処理し、削除されたロールに対応した通知の処理をスキップする修正を加えました。
具体的には、roleEntityService.pack(notification.roleId)を実行する際に、ロールが存在しない場合にはEntityNotFoundErrorをキャッチして、nullを返すように変更しています。
これにより、通知が「エラーが発生しました」と表示される問題を解消します。

また、不要なESLintの注釈がエディタの機能により自動的に削除されています。

Why

現在、削除されたロールを参照しようとすると、DBからnullが返ってきて例外が発生し、ユーザーにはエラーメッセージしか表示されなくなってしまいます。
この問題を解消するために、削除されたロールに関連する通知の処理をスキップするようにしました。
これにより、ユーザーに対して不要なエラーメッセージが表示されることがなくなります。

Additional info (optional)

ローカル環境でのテストを行い、問題が解消されたことを確認しています。

Checklist

  • Read the contribution guide
  • Test working in a local environment
  • (If needed) Add story of storybook
  • (If needed) Update CHANGELOG.md
  • (If possible) Add tests

@github-actions github-actions bot added the packages/backend Server side specific issue/PR label Sep 5, 2024
Copy link
Contributor

github-actions bot commented Sep 5, 2024

このPRによるapi.jsonの差分

差分はこちら

Get diff files from Workflow Page

Copy link

codecov bot commented Sep 5, 2024

Codecov Report

Attention: Patch coverage is 60.00000% with 2 lines in your changes missing coverage. Please review.

Project coverage is 39.63%. Comparing base (2cbe1d1) to head (849e7ff).

Files with missing lines Patch % Lines
...end/src/core/entities/NotificationEntityService.ts 60.00% 2 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #14500      +/-   ##
===========================================
- Coverage    41.37%   39.63%   -1.74%     
===========================================
  Files         1543     1539       -4     
  Lines       196679   190971    -5708     
  Branches      3547     3504      -43     
===========================================
- Hits         81371    75688    -5683     
+ Misses      114714   114689      -25     
  Partials       594      594              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- catchブロックでのeという変数名は混同の危険性があるため利用しない
- 保守性のため型チェックでのエラーハンドリングを行う
@@ -140,7 +139,10 @@ export class NotificationEntityService implements OnModuleInit {
// #endregion

const needsRole = notification.type === 'roleAssigned';
const role = needsRole ? await this.roleEntityService.pack(notification.roleId) : undefined;
const role = needsRole ? await this.roleEntityService.pack(notification.roleId).catch((err) => {
if (err instanceof EntityNotFoundError) return null;
Copy link
Author

@hinanoaira hinanoaira Sep 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここはApiではないのでApiErrorを使わない。
元々ロールが処理されておりnullが返ってきたときの処理が直後にあったのでその意向に従い、このreturnでnullはroleに入り、直後の if(needsRole && !role) でロールが削除されていた時の処理に入り、メソッドを抜ける

@kakkokari-gtyih kakkokari-gtyih added this to the v2024.9.0 milestone Sep 9, 2024
@syuilo
Copy link
Member

syuilo commented Sep 14, 2024

様々なPRは #13929 (comment) が終わってから入れます🙏

@kakkokari-gtyih
Copy link
Contributor

kakkokari-gtyih commented Sep 14, 2024

様々なPRは #13929 (comment) が終わってから入れます🙏

Off topic: リバートのリバートが用意できてもそれを入れるには #14529 での議論を完了させる必要がある気がする

@syuilo
Copy link
Member

syuilo commented Sep 14, 2024

それはあまり関係なさそう

@syuilo
Copy link
Member

syuilo commented Sep 14, 2024

様々なPRは #13929 (comment) が終わってから入れます🙏

入れてからというよりPRがある状態になってから

@kakkokari-gtyih
Copy link
Contributor

様々なPRは #13929 (comment) が終わってから入れます🙏

#14546

@syuilo
Copy link
Member

syuilo commented Sep 15, 2024

roleEntityService.packがエラーをハンドリングしてEntityNotFoundError以外の方法でエラーを表現するようになった場合に壊れそうという懸念があるわね

@syuilo
Copy link
Member

syuilo commented Sep 15, 2024

EntityNotFoundErrorはTypeORMのエラーなので実際にそうなる可能性は少なくない

@syuilo
Copy link
Member

syuilo commented Sep 15, 2024

TypeScriptでその関数がどのようなエラーを発生させる可能性があるかを型定義できたりすれば解決するけどできない気がする
からError以外の(型を使える)方法でエラーを表現するかID付きエラーを使うようにすれば良さそう

@kakkokari-gtyih kakkokari-gtyih removed this from the v2024.9.0 milestone Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
packages/backend Server side specific issue/PR
Projects
None yet
4 participants