From 931d3b6488112e9599297f3896ee59412a91a741 Mon Sep 17 00:00:00 2001 From: atsu1125 Date: Thu, 15 Sep 2022 01:56:18 +0900 Subject: [PATCH] =?UTF-8?q?fix:=20To=20make=20return=20400=20when=20drive?= =?UTF-8?q?=20limit=20is=20exceeded=20=E3=83=89=E3=83=A9=E3=82=A4=E3=83=96?= =?UTF-8?q?=E4=B8=8A=E9=99=90=E8=B6=85=E9=81=8E=E3=81=AFInternal=20Error?= =?UTF-8?q?=E3=81=A7=E3=81=AF=E3=81=AA=E3=81=8FBad=20Request?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/server/api/endpoints/drive/files/create.ts | 16 ++++++++++++++-- src/services/drive/add-file.ts | 3 ++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/server/api/endpoints/drive/files/create.ts b/src/server/api/endpoints/drive/files/create.ts index 61055c5d18..0737ff2157 100644 --- a/src/server/api/endpoints/drive/files/create.ts +++ b/src/server/api/endpoints/drive/files/create.ts @@ -6,6 +6,7 @@ import define from '../../../define'; import { apiLogger } from '../../../logger'; import { ApiError } from '../../../error'; import { DriveFiles } from '../../../../../models'; +import { IdentifiableError } from '../../../../../misc/identifiable-error'; export const meta = { desc: { @@ -74,7 +75,13 @@ export const meta = { message: 'Invalid file name.', code: 'INVALID_FILE_NAME', id: 'f449b209-0c60-4e51-84d5-29486263bfd4' - } + }, + + noFreeSpace: { + message: 'Cannot upload the file because you have no free space of drive.', + code: 'NO_FREE_SPACE', + id: 'd08dbc37-a6a9-463a-8c47-96c32ab5f064', + }, } }; @@ -99,7 +106,12 @@ export default define(meta, async (ps, user, app, file, cleanup) => { const driveFile = await create(user, file.path, name, null, ps.folderId, ps.force, false, null, null, ps.isSensitive); return await DriveFiles.pack(driveFile, { self: true }); } catch (e) { - apiLogger.error(e); + if (e instanceof Error || typeof e === 'string') { + apiLogger.error(e); + } + if (e instanceof IdentifiableError) { + if (e.id === 'c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6') throw new ApiError(meta.errors.noFreeSpace); + } throw new ApiError(); } finally { cleanup!(); diff --git a/src/services/drive/add-file.ts b/src/services/drive/add-file.ts index 18d45c7b00..fcd09759dc 100644 --- a/src/services/drive/add-file.ts +++ b/src/services/drive/add-file.ts @@ -20,6 +20,7 @@ import { genId } from '../../misc/gen-id'; import { isDuplicateKeyValueError } from '../../misc/is-duplicate-key-value-error'; import * as S3 from 'aws-sdk/clients/s3'; import { getS3 } from './s3'; +import { IdentifiableError } from '../../misc/identifiable-error'; const logger = driveLogger.createSubLogger('register', 'yellow'); @@ -331,7 +332,7 @@ export default async function( // If usage limit exceeded if (usage + info.size > driveCapacity) { if (Users.isLocalUser(user)) { - throw new Error('no-free-space'); + throw new IdentifiableError('c6244ed2-a39a-4e1c-bf93-f0fbd7764fa6', 'No free space.'); } else { // (アバターまたはバナーを含まず)最も古いファイルを削除する deleteOldFile(user as IRemoteUser);