[mastodon-client] Handle ApiError in CatchErrorsMiddleware

This commit is contained in:
Laura Hausmann 2023-10-06 03:09:22 +02:00
parent a3d2330f26
commit 8bc7bf373e
No known key found for this signature in database
GPG key ID: D044E84C5BE01605

View file

@ -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) {