fix: エラーハンドリングでの保守性の確保

- catchブロックでのeという変数名は混同の危険性があるため利用しない
- 保守性のため型チェックでのエラーハンドリングを行う
This commit is contained in:
HinanoAira 2024-09-08 04:11:22 +09:00
parent 41f65a20f1
commit 8b0f3e7fa5
No known key found for this signature in database
GPG Key ID: 7FBE088453C8B50C
1 changed files with 4 additions and 4 deletions

View File

@ -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';
@ -139,9 +139,9 @@ export class NotificationEntityService implements OnModuleInit {
// #endregion
const needsRole = notification.type === 'roleAssigned';
const role = needsRole ? await this.roleEntityService.pack(notification.roleId).catch((e) => {
if (e.name === 'EntityNotFoundError') return null;
throw e;
const role = needsRole ? await this.roleEntityService.pack(notification.roleId).catch((err) => {
if (err instanceof EntityNotFoundError) return null;
throw err;
}) : undefined;
// if the role has been deleted, don't show this notification
if (needsRole && !role) {