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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import { Inject, Injectable } from '@nestjs/common';
import { ModuleRef } from '@nestjs/core';
import { In } from 'typeorm';
import { EntityNotFoundError, In } from 'typeorm';
import { DI } from '@/di-symbols.js';
import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js';
import { awaitAll } from '@/misc/prelude/await-all.js';
Expand Down Expand Up @@ -59,7 +59,6 @@ export class NotificationEntityService implements OnModuleInit {
async #packInternal <T extends MiNotification | MiGroupedNotification> (
src: T,
meId: MiUser['id'],
// eslint-disable-next-line @typescript-eslint/ban-types
options: {
checkValidNotifier?: boolean;
},
Expand Down Expand Up @@ -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) でロールが削除されていた時の処理に入り、メソッドを抜ける

throw err;
}) : undefined;
// if the role has been deleted, don't show this notification
if (needsRole && !role) {
return null;
Expand Down Expand Up @@ -229,7 +231,6 @@ export class NotificationEntityService implements OnModuleInit {
public async pack(
src: MiNotification | MiGroupedNotification,
meId: MiUser['id'],
// eslint-disable-next-line @typescript-eslint/ban-types
options: {
checkValidNotifier?: boolean;
},
Expand Down
Loading