mirror of
https://github.com/spacebarchat/server.git
synced 2026-09-17 01:35:26 +00:00
@@ -5,11 +5,11 @@ import { checkToken, Config } from "@fosscord/util";
|
||||
export const NO_AUTHORIZATION_ROUTES = [
|
||||
"/auth/login",
|
||||
"/auth/register",
|
||||
"/webhooks/",
|
||||
"/ping",
|
||||
"/gateway",
|
||||
"/experiments",
|
||||
/\/guilds\/\d+\/widget\.(json|png)/,
|
||||
/\/webhooks\/\d+\/\w+/ // only exclude webhook calls with webhook token
|
||||
/\/guilds\/\d+\/widget\.(json|png)/
|
||||
];
|
||||
|
||||
export const API_PREFIX = /^\/api(\/v\d+)?/;
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { NextFunction, Request, Response } from "express";
|
||||
import { HTTPError } from "lambert-server";
|
||||
import { EntityNotFoundError } from "typeorm";
|
||||
import { FieldError } from "@fosscord/api";
|
||||
import { ApiError } from "@fosscord/util";
|
||||
|
||||
const EntityNotFoundErrorRegex = /"(\w+)"/;
|
||||
|
||||
export function ErrorHandler(error: Error, req: Request, res: Response, next: NextFunction) {
|
||||
if (!error) return next();
|
||||
|
||||
@@ -19,8 +18,8 @@ export function ErrorHandler(error: Error, req: Request, res: Response, next: Ne
|
||||
code = error.code;
|
||||
message = error.message;
|
||||
httpcode = error.httpStatus;
|
||||
} else if (error.name === "EntityNotFoundError") {
|
||||
message = `${error.message.match(EntityNotFoundErrorRegex)?.[1] || "Item"} could not be found`;
|
||||
} else if (error instanceof EntityNotFoundError) {
|
||||
message = `${(error as any).stringifyTarget || "Item"} could not be found`;
|
||||
code = 404;
|
||||
} else if (error instanceof FieldError) {
|
||||
code = Number(error.code);
|
||||
|
||||
Reference in New Issue
Block a user