[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 { MastoContext, logger } from "@/server/api/mastodon/index.js";
|
||||||
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
import { IdentifiableError } from "@/misc/identifiable-error.js";
|
||||||
|
import { ApiError } from "@/server/api/error.js";
|
||||||
|
|
||||||
export class MastoApiError extends Error {
|
export class MastoApiError extends Error {
|
||||||
statusCode: number;
|
statusCode: number;
|
||||||
|
@ -29,6 +30,9 @@ export async function CatchErrorsMiddleware(ctx: MastoContext, next: () => Promi
|
||||||
else if (e instanceof IdentifiableError) {
|
else if (e instanceof IdentifiableError) {
|
||||||
ctx.status = 400;
|
ctx.status = 400;
|
||||||
}
|
}
|
||||||
|
else if (e instanceof ApiError) {
|
||||||
|
ctx.status = e.httpStatusCode ?? 500;
|
||||||
|
}
|
||||||
else {
|
else {
|
||||||
logger.error(`Error occured in ${ctx.method} ${ctx.path}:`);
|
logger.error(`Error occured in ${ctx.method} ${ctx.path}:`);
|
||||||
if (e instanceof Error) {
|
if (e instanceof Error) {
|
||||||
|
|
Loading…
Reference in a new issue