From 38d1fde84f4d732d354022078674d6d23e577df7 Mon Sep 17 00:00:00 2001
From: GyDi <segydi@foxmail.com>
Date: Tue, 11 Oct 2022 22:51:18 +0800
Subject: [PATCH] fix: api error handle

---
 src/services/api.ts | 42 +++++++++++++++++-------------------------
 1 file changed, 17 insertions(+), 25 deletions(-)

diff --git a/src/services/api.ts b/src/services/api.ts
index 5f09bef..f25b3cb 100644
--- a/src/services/api.ts
+++ b/src/services/api.ts
@@ -88,13 +88,9 @@ export async function updateProxy(group: string, proxy: string) {
 
 // get proxy
 async function getProxiesInner() {
-  try {
-    const instance = await getAxios();
-    const response = await instance.get<any, any>("/proxies");
-    return (response?.proxies || {}) as Record<string, ApiType.ProxyItem>;
-  } catch {
-    return {};
-  }
+  const instance = await getAxios();
+  const response = await instance.get<any, any>("/proxies");
+  return (response?.proxies || {}) as Record<string, ApiType.ProxyItem>;
 }
 
 /// Get the Proxy information
@@ -151,24 +147,20 @@ export async function getProxies() {
 
 // get proxy providers
 export async function getProviders() {
-  try {
-    const instance = await getAxios();
-    const response = await instance.get<any, any>("/providers/proxies");
-
-    const providers = (response.providers || {}) as Record<
-      string,
-      ApiType.ProviderItem
-    >;
-
-    return Object.fromEntries(
-      Object.entries(providers).filter(([key, item]) => {
-        const type = item.vehicleType.toLowerCase();
-        return type === "http" || type === "file";
-      })
-    );
-  } catch {
-    return {};
-  }
+  const instance = await getAxios();
+  const response = await instance.get<any, any>("/providers/proxies");
+
+  const providers = (response.providers || {}) as Record<
+    string,
+    ApiType.ProviderItem
+  >;
+
+  return Object.fromEntries(
+    Object.entries(providers).filter(([key, item]) => {
+      const type = item.vehicleType.toLowerCase();
+      return type === "http" || type === "file";
+    })
+  );
 }
 
 // proxy providers health check
-- 
GitLab