show detail error to api test

This commit is contained in:
Gabe Yuan
2023-11-02 23:35:36 +08:00
parent 84de1e0f12
commit 94288b5dc3
3 changed files with 23 additions and 4 deletions

View File

@@ -127,7 +127,13 @@ export const fetchData = async (
}
if (!res?.ok) {
throw new Error(`response: ${res.statusText}`);
const cause = {
status: res.status,
};
if (res.headers.get("Content-Type")?.includes("json")) {
cause.body = await res.json();
}
throw new Error(`response: [${res.status}] ${res.statusText}`, { cause });
}
// 插入缓存
@@ -163,7 +169,7 @@ export const fetchPolyfill = async (input, opts) => {
if (isExt && !isBg()) {
const res = await sendBgMsg(MSG_FETCH, { input, opts });
if (res.error) {
throw new Error(res.error);
throw new Error(res.error, { cause: res.cause });
}
return res.data;
}