Skip to content

Commit 80c1b19

Browse files
committed
chore: lower resource loader failure log level
1 parent d854388 commit 80c1b19

2 files changed

Lines changed: 47 additions & 2 deletions

File tree

packages/sdk/src/resource-loader.test.ts

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
1-
import { describe, expect, test, beforeEach, vi, type Mock } from "vitest";
1+
import {
2+
afterEach,
3+
describe,
4+
expect,
5+
test,
6+
beforeEach,
7+
vi,
8+
type Mock,
9+
} from "vitest";
210

311
import { loadResource } from "./resource-loader";
412
import type { ResourceRequest } from "./schema/resources";
@@ -13,6 +21,10 @@ describe("loadResource", () => {
1321
vi.clearAllMocks();
1422
});
1523

24+
afterEach(() => {
25+
vi.restoreAllMocks();
26+
});
27+
1628
test("should successfully fetch a resource and return a JSON response", async () => {
1729
const mockResponse = new Response(JSON.stringify({ key: "value" }), {
1830
status: 200,
@@ -156,4 +168,37 @@ describe("loadResource", () => {
156168
]),
157169
});
158170
});
171+
172+
test("should log failed resource responses as info", async () => {
173+
const consoleError = vi
174+
.spyOn(console, "error")
175+
.mockImplementation(() => {});
176+
const consoleInfo = vi.spyOn(console, "info").mockImplementation(() => {});
177+
const mockResponse = new Response("not found", {
178+
status: 404,
179+
});
180+
mockFetch.mockResolvedValue(mockResponse);
181+
182+
const resourceRequest: ResourceRequest = {
183+
name: "resource",
184+
url: "https://example.com/resource",
185+
searchParams: [],
186+
method: "get",
187+
headers: [],
188+
body: undefined,
189+
};
190+
191+
const result = await loadResource(mockFetch, resourceRequest);
192+
193+
expect(result).toEqual({
194+
data: "not found",
195+
ok: false,
196+
status: 404,
197+
statusText: "",
198+
});
199+
expect(consoleError).not.toHaveBeenCalled();
200+
expect(consoleInfo).toHaveBeenCalledWith(
201+
'Failed to load resource: https://example.com/resource - 404: "not found"'
202+
);
203+
});
159204
});

packages/sdk/src/resource-loader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ export const loadResource = async (
6666
}
6767

6868
if (!response.ok) {
69-
console.error(
69+
console.info(
7070
`Failed to load resource: ${href} - ${response.status}: ${JSON.stringify(data).slice(0, 300)}`
7171
);
7272
}

0 commit comments

Comments
 (0)