Skip to content

Commit 0419300

Browse files
committed
Update fetch.ts
1 parent b2cc72b commit 0419300

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

src/lib/api/fetch.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,11 @@ const contentTypeHeader = 'Content-Type';
1212

1313
// fetchApiServer is a wrapper around fetch that adds the necessary headers for the Crate API or the MCP API server.
1414
export const parseJsonOrText = async (res: Response): Promise<unknown> => {
15+
const text = await res.text();
1516
try {
16-
return await res.json();
17+
return JSON.parse(text);
1718
} catch {
18-
try {
19-
return await res.text();
20-
} catch {
21-
return '';
22-
}
19+
return text;
2320
}
2421
};
2522

@@ -78,9 +75,12 @@ export const fetchApiServerJson = async <T>(
7875
jq?: string,
7976
httpMethod: string = 'GET',
8077
body?: BodyInit,
81-
): Promise<T> => {
78+
): Promise<T | string> => {
8279
const res = await fetchApiServer(path, config, jq, httpMethod, body);
8380
const data = await parseJsonOrText(res);
81+
if (typeof data === 'string') {
82+
return data as string;
83+
}
8484
return data as T;
8585
};
8686

0 commit comments

Comments
 (0)