fix: event type not found 400 and other (#23904)
* fix: various fixes specifically to event-types * Revamp error handling a little; highly flawed * fix: Test cases that depended on defaultResponder behaviour --------- Co-authored-by: Udit Takkar <[email protected]> Co-authored-by: Morgan <[email protected]>
This commit is contained in:
13 files changed
+158
-174
No files matched your search
@@ -39,23 +39,4 @@ describe("defaultHandler Test Suite", () => {
|
||||
|
||||
expect(getHandler).toHaveBeenCalledWith(req, res);
|
||||
});
|
||||
|
||||
it("should return 500 for errors thrown in handler", async () => {
|
||||
const getHandler = vi.fn().mockRejectedValue(new Error("Test Error"));
|
||||
const handlers = {
|
||||
GET: { default: getHandler },
|
||||
};
|
||||
const handler = defaultHandler(handlers);
|
||||
|
||||
const { req, res } = createMocks({
|
||||
method: "GET",
|
||||
});
|
||||
|
||||
await handler(req, res);
|
||||
|
||||
expect(res._getStatusCode()).toBe(500);
|
||||
expect(res._getJSONData()).toEqual({
|
||||
message: "Something went wrong",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -13,12 +13,5 @@ export const defaultHandler = (handlers: Handlers) => async (req: NextApiRequest
|
||||
.status(405)
|
||||
.json({ message: `Method Not Allowed (Allow: ${Object.keys(handlers).join(",")})` });
|
||||
}
|
||||
|
||||
try {
|
||||
await handler(req, res);
|
||||
return;
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
return res.status(500).json({ message: "Something went wrong" });
|
||||
}
|
||||
return await handler(req, res);
|
||||
};
|
||||
Reference in new issue
Block a user