From 8bc7bf373ed235c0a5aa3fb7d05c2fe64e53c7bf Mon Sep 17 00:00:00 2001 From: Laura Hausmann Date: Fri, 6 Oct 2023 03:09:22 +0200 Subject: [PATCH] [mastodon-client] Handle ApiError in CatchErrorsMiddleware --- .../src/server/api/mastodon/middleware/catch-errors.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/packages/backend/src/server/api/mastodon/middleware/catch-errors.ts b/packages/backend/src/server/api/mastodon/middleware/catch-errors.ts index f11306cee..918ce1ce6 100644 --- a/packages/backend/src/server/api/mastodon/middleware/catch-errors.ts +++ b/packages/backend/src/server/api/mastodon/middleware/catch-errors.ts @@ -1,5 +1,6 @@ import { MastoContext, logger } from "@/server/api/mastodon/index.js"; import { IdentifiableError } from "@/misc/identifiable-error.js"; +import { ApiError } from "@/server/api/error.js"; export class MastoApiError extends Error { statusCode: number; @@ -29,6 +30,9 @@ export async function CatchErrorsMiddleware(ctx: MastoContext, next: () => Promi else if (e instanceof IdentifiableError) { ctx.status = 400; } + else if (e instanceof ApiError) { + ctx.status = e.httpStatusCode ?? 500; + } else { logger.error(`Error occured in ${ctx.method} ${ctx.path}:`); if (e instanceof Error) {