diff --git a/packages/lib/server/defaultHandler.ts b/packages/lib/server/defaultHandler.ts index bd2b2c4a92..ded7ad9956 100644 --- a/packages/lib/server/defaultHandler.ts +++ b/packages/lib/server/defaultHandler.ts @@ -4,11 +4,15 @@ type Handlers = { [method in "GET" | "POST" | "PATCH" | "PUT" | "DELETE"]?: Promise<{ default: NextApiHandler }>; }; -/** Allows us to split big API handlers by method and auto catch unsupported methods */ +/** Allows us to split big API handlers by method */ const defaultHandler = (handlers: Handlers) => async (req: NextApiRequest, res: NextApiResponse) => { const handler = (await handlers[req.method as keyof typeof handlers])?.default; - - if (!handler) return res.status(405).json({ message: "Method not allowed" }); + // auto catch unsupported methods. + if (!handler) { + return res + .status(405) + .json({ message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})` }); + } try { await handler(req, res);