fix: エラーハンドリングでの保守性の確保
- catchブロックでのeという変数名は混同の危険性があるため利用しない - 保守性のため型チェックでのエラーハンドリングを行う
This commit is contained in:
parent
41f65a20f1
commit
8b0f3e7fa5
|
@ -5,7 +5,7 @@
|
||||||
|
|
||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { ModuleRef } from '@nestjs/core';
|
import { ModuleRef } from '@nestjs/core';
|
||||||
import { In } from 'typeorm';
|
import { EntityNotFoundError, In } from 'typeorm';
|
||||||
import { DI } from '@/di-symbols.js';
|
import { DI } from '@/di-symbols.js';
|
||||||
import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js';
|
import type { FollowRequestsRepository, NotesRepository, MiUser, UsersRepository } from '@/models/_.js';
|
||||||
import { awaitAll } from '@/misc/prelude/await-all.js';
|
import { awaitAll } from '@/misc/prelude/await-all.js';
|
||||||
|
@ -139,9 +139,9 @@ export class NotificationEntityService implements OnModuleInit {
|
||||||
// #endregion
|
// #endregion
|
||||||
|
|
||||||
const needsRole = notification.type === 'roleAssigned';
|
const needsRole = notification.type === 'roleAssigned';
|
||||||
const role = needsRole ? await this.roleEntityService.pack(notification.roleId).catch((e) => {
|
const role = needsRole ? await this.roleEntityService.pack(notification.roleId).catch((err) => {
|
||||||
if (e.name === 'EntityNotFoundError') return null;
|
if (err instanceof EntityNotFoundError) return null;
|
||||||
throw e;
|
throw err;
|
||||||
}) : undefined;
|
}) : undefined;
|
||||||
// if the role has been deleted, don't show this notification
|
// if the role has been deleted, don't show this notification
|
||||||
if (needsRole && !role) {
|
if (needsRole && !role) {
|
||||||
|
|
Loading…
Reference in New Issue