mirror of
https://iceshrimp.dev/limepotato/jormungandr-bite.git
synced 2024-11-13 13:37:31 -07:00
[mastodon-client] Handle ApiError in CatchErrorsMiddleware
This commit is contained in:
parent
a3d2330f26
commit
8bc7bf373e
1 changed files with 4 additions and 0 deletions
|
@ -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 a new issue