refactor: webapi http

This commit is contained in:
手瓜一十雪
2024-05-13 21:22:20 +08:00
parent 8fe7d3aaec
commit 7ecd479b3e
2 changed files with 7 additions and 2 deletions

View File

@@ -61,7 +61,12 @@ export class RequestUtil {
requestInit.headers = new Headers(headers);
}
try {
const response = await fetch(url, { ...requestInit, body: data });
let response;
if (method.toUpperCase() === 'POST') {
response = await fetch(url, { ...requestInit, body: data });
} else {
response = await fetch(url, { ...requestInit });
}
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}