From 3a04c66ee1e8d1deafa224c881f7a0ca7be8c668 Mon Sep 17 00:00:00 2001 From: syuilo Date: Fri, 4 Feb 2022 02:06:24 +0900 Subject: [PATCH] refactor --- .../backend/src/server/api/endpoints/drive/files/create.ts | 4 +++- .../backend/src/server/api/endpoints/following/create.ts | 7 +++++-- .../src/server/api/endpoints/following/requests/cancel.ts | 5 ++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/packages/backend/src/server/api/endpoints/drive/files/create.ts b/packages/backend/src/server/api/endpoints/drive/files/create.ts index 877e76677..ac7863ec7 100644 --- a/packages/backend/src/server/api/endpoints/drive/files/create.ts +++ b/packages/backend/src/server/api/endpoints/drive/files/create.ts @@ -86,7 +86,9 @@ export default define(meta, async (ps, user, _, file, cleanup) => { const driveFile = await addFile({ user, path: file.path, name, comment: ps.comment, folderId: ps.folderId, force: ps.force, sensitive: ps.isSensitive }); return await DriveFiles.pack(driveFile, { self: true }); } catch (e) { - apiLogger.error(e); + if (e instanceof Error || typeof e === 'string') { + apiLogger.error(e); + } throw new ApiError(); } finally { cleanup!(); diff --git a/packages/backend/src/server/api/endpoints/following/create.ts b/packages/backend/src/server/api/endpoints/following/create.ts index 96aede455..b840ab769 100644 --- a/packages/backend/src/server/api/endpoints/following/create.ts +++ b/packages/backend/src/server/api/endpoints/following/create.ts @@ -6,6 +6,7 @@ import define from '../../define'; import { ApiError } from '../../error'; import { getUser } from '../../common/getters'; import { Followings, Users } from '@/models/index'; +import { IdentifiableError } from '@/misc/identifiable-error'; export const meta = { tags: ['following', 'users'], @@ -92,8 +93,10 @@ export default define(meta, async (ps, user) => { try { await create(follower, followee); } catch (e) { - if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(meta.errors.blocking); - if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(meta.errors.blocked); + if (e instanceof IdentifiableError) { + if (e.id === '710e8fb0-b8c3-4922-be49-d5d93d8e6a6e') throw new ApiError(meta.errors.blocking); + if (e.id === '3338392a-f764-498d-8855-db939dcf8c48') throw new ApiError(meta.errors.blocked); + } throw e; } diff --git a/packages/backend/src/server/api/endpoints/following/requests/cancel.ts b/packages/backend/src/server/api/endpoints/following/requests/cancel.ts index 19ed02c15..c9abbf36d 100644 --- a/packages/backend/src/server/api/endpoints/following/requests/cancel.ts +++ b/packages/backend/src/server/api/endpoints/following/requests/cancel.ts @@ -5,6 +5,7 @@ import define from '../../../define'; import { ApiError } from '../../../error'; import { getUser } from '../../../common/getters'; import { Users } from '@/models/index'; +import { IdentifiableError } from '@/misc/identifiable-error'; export const meta = { tags: ['following', 'account'], @@ -51,7 +52,9 @@ export default define(meta, async (ps, user) => { try { await cancelFollowRequest(followee, user); } catch (e) { - if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound); + if (e instanceof IdentifiableError) { + if (e.id === '17447091-ce07-46dd-b331-c1fd4f15b1e7') throw new ApiError(meta.errors.followRequestNotFound); + } throw e; }