From b52985ffcce7b2c74272ad97c677589673f73539 Mon Sep 17 00:00:00 2001 From: Johnson Liang Date: Mon, 18 Nov 2024 15:01:21 +0800 Subject: [PATCH] fix(adm): throw HTTPError for user errors --- src/adm/handlers/moderation/blockUser.ts | 3 ++- src/adm/index.ts | 4 +++- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/adm/handlers/moderation/blockUser.ts b/src/adm/handlers/moderation/blockUser.ts index eff9ec5b..805cfcc0 100644 --- a/src/adm/handlers/moderation/blockUser.ts +++ b/src/adm/handlers/moderation/blockUser.ts @@ -4,6 +4,7 @@ * * Please announce that the user will be blocked openly with a URL first. */ +import { HTTPError } from 'fets'; import client from 'util/client'; import getAllDocs from 'util/getAllDocs'; @@ -47,7 +48,7 @@ async function writeBlockedReasonToUser(userId: string, blockedReason: string) { 'message' in e && e.message === 'document_missing_exception' ) { - throw new Error(`User with ID=${userId} does not exist`); + throw new HTTPError(400, `User with ID=${userId} does not exist`); } throw e; diff --git a/src/adm/index.ts b/src/adm/index.ts index 2ac2ce7f..90521374 100644 --- a/src/adm/index.ts +++ b/src/adm/index.ts @@ -71,7 +71,9 @@ const router = createRouter({ { additionalProperties: false } ), }, - responses: { 200: Type.Object({ success: Type.Boolean() }) }, + responses: { + 200: Type.Object({ success: Type.Boolean() }), + }, }, handler: async (request) => Response.json(await blockUser(await request.json())),