Forráskód Böngészése

put 错误处理和 post 统一

visuddhinanda 2 éve
szülő
commit
5993ef1424
1 módosított fájl, 4 hozzáadás és 8 törlés
  1. 4 8
      dashboard/src/request.ts

+ 4 - 8
dashboard/src/request.ts

@@ -93,19 +93,15 @@ export const patch = <Request, Response>(
   });
 };
 
-export const put = <Request, Response>(
+export const put = async <Request, Response>(
   path: string,
   body: Request
 ): Promise<Response> => {
   const data = options("PUT");
   data.body = JSON.stringify(body);
-  return fetch(backend(path), data).then((res) =>
-    res.status === 200
-      ? res.json()
-      : res.json().then((err) => {
-          throw err;
-        })
-  );
+  const response = await fetch(backend(path), data);
+  const res: Response = await response.json();
+  return res;
 };
 
 export const download = (path: string, name: string) => {