mirror of
https://iceshrimp.dev/crimekillz/trashposs
synced 2024-11-22 00:43:49 +01:00
[mastodon-client] Handle ApiError in CatchErrorsMiddleware
This commit is contained in:
parent
a3d2330f26
commit
8bc7bf373e
@ -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) {
|
||||
|
Loading…
Reference in New Issue
Block a user