mirror of
https://github.com/gethomepage/homepage.git
synced 2026-09-12 15:15:58 -07:00
Fix: Await async proxy handlers (#6371)
This commit is contained in:
@@ -344,4 +344,17 @@ describe("pages/api/services/proxy", () => {
|
|||||||
expect(res.statusCode).toBe(500);
|
expect(res.statusCode).toBe(500);
|
||||||
expect(res.body).toEqual({ error: "Unexpected error" });
|
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" });
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ export default async function handler(req, res) {
|
|||||||
if (serviceProxyHandler instanceof Function) {
|
if (serviceProxyHandler instanceof Function) {
|
||||||
// quick return for no endpoint services, calendar is an exception
|
// quick return for no endpoint services, calendar is an exception
|
||||||
if (!req.query.endpoint || serviceProxyHandler === calendarProxyHandler) {
|
if (!req.query.endpoint || serviceProxyHandler === calendarProxyHandler) {
|
||||||
return serviceProxyHandler(req, res);
|
return await serviceProxyHandler(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
// map opaque endpoints to their actual endpoint
|
// map opaque endpoints to their actual endpoint
|
||||||
@@ -90,15 +90,15 @@ export default async function handler(req, res) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (endpointProxy instanceof Function) {
|
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 instanceof RegExp) {
|
||||||
if (widget.allowedEndpoints.test(req.query.endpoint)) {
|
if (widget.allowedEndpoints.test(req.query.endpoint)) {
|
||||||
return serviceProxyHandler(req, res);
|
return await serviceProxyHandler(req, res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user