Fix: Await async proxy handlers (#6371)

This commit is contained in:
shamoon
2026-02-28 11:22:54 -08:00
committed by GitHub
parent d529f81cb4
commit 29e2502d74
2 changed files with 17 additions and 4 deletions

View File

@@ -344,4 +344,17 @@ describe("pages/api/services/proxy", () => {
expect(res.statusCode).toBe(500);
expect(res.body).toEqual({ error: "Unexpected error" });
});
it("returns 500 when an async proxy handler throws", async () => {
getServiceWidget.mockResolvedValue({ type: "linkwarden" });
handlerFn.handler.mockRejectedValueOnce(new Error("proxy boom"));
const req = { method: "GET", query: { group: "g", service: "s", index: "0" } };
const res = createMockRes();
await servicesProxy(req, res);
expect(res.statusCode).toBe(500);
expect(res.body).toEqual({ error: "Unexpected error" });
});
});

View File

@@ -29,7 +29,7 @@ export default async function handler(req, res) {
if (serviceProxyHandler instanceof Function) {
// quick return for no endpoint services, calendar is an exception
if (!req.query.endpoint || serviceProxyHandler === calendarProxyHandler) {
return serviceProxyHandler(req, res);
return await serviceProxyHandler(req, res);
}
// map opaque endpoints to their actual endpoint
@@ -90,15 +90,15 @@ export default async function handler(req, res) {
}
if (endpointProxy instanceof Function) {
return endpointProxy(req, res, map);
return await endpointProxy(req, res, map);
}
return serviceProxyHandler(req, res, map);
return await serviceProxyHandler(req, res, map);
}
if (widget.allowedEndpoints instanceof RegExp) {
if (widget.allowedEndpoints.test(req.query.endpoint)) {
return serviceProxyHandler(req, res);
return await serviceProxyHandler(req, res);
}
}