[weather] add error handling to weather fetch functions, including cors (#3791)

Co-authored-by: Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>
fixes #3687
This commit is contained in:
sam detweiler
2025-11-08 07:21:31 -06:00
committed by GitHub
parent 3b79791a6b
commit c1aaea5913
5 changed files with 71 additions and 56 deletions

View File

@@ -16,7 +16,8 @@ describe("server_functions tests", () => {
headers: {
get: fetchResponseHeadersGet
},
text: fetchResponseHeadersText
text: fetchResponseHeadersText,
ok: true
};
fetch = vi.fn();
@@ -26,7 +27,12 @@ describe("server_functions tests", () => {
corsResponse = {
set: vi.fn(() => {}),
send: vi.fn(() => {})
send: vi.fn(() => {}),
status: vi.fn(function (code) {
this.statusCode = code;
return this;
}),
json: vi.fn(() => {})
};
request = {
@@ -91,15 +97,11 @@ describe("server_functions tests", () => {
throw error;
});
let sentData;
corsResponse.send = vi.fn((input) => {
sentData = input;
});
await cors(request, corsResponse);
expect(fetchResponseHeadersText.mock.calls).toHaveLength(1);
expect(sentData).toBe(error);
expect(corsResponse.status).toHaveBeenCalledWith(500);
expect(corsResponse.json).toHaveBeenCalledWith({ error: error.message });
});
it("Fetches with user agent by default", async () => {