fix(ai): 网络失败时显示友好提示,不再直接展示 Failed to fetch
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
||||
PeqState,
|
||||
} from "@/lib/luxsinApi";
|
||||
import { getDeviceIpFromUrl, resolveInitialDeviceIp } from "@/lib/deviceIp";
|
||||
import { isLikelyNetworkFetchError } from "@/lib/networkError";
|
||||
|
||||
interface DeviceContextType {
|
||||
ip: string;
|
||||
@@ -115,7 +116,11 @@ export function DeviceProvider({ children }: { children: React.ReactNode }) {
|
||||
setApi(newApi);
|
||||
setIsConnected(true);
|
||||
} catch (e) {
|
||||
setError(`Connection failed: ${e instanceof Error ? e.message : String(e)}`);
|
||||
setError(
|
||||
isLikelyNetworkFetchError(e)
|
||||
? null
|
||||
: `Connection failed: ${e instanceof Error ? e.message : String(e)}`,
|
||||
);
|
||||
setIsConnected(false);
|
||||
} finally {
|
||||
setIsConnecting(false);
|
||||
@@ -151,7 +156,11 @@ export function DeviceProvider({ children }: { children: React.ReactNode }) {
|
||||
await fetchState(apiInstance);
|
||||
await fetchPeqState(apiInstance).catch(() => undefined);
|
||||
} catch (e) {
|
||||
setError(`Refresh failed: ${e instanceof Error ? e.message : String(e)}`);
|
||||
setError(
|
||||
isLikelyNetworkFetchError(e)
|
||||
? null
|
||||
: `Refresh failed: ${e instanceof Error ? e.message : String(e)}`,
|
||||
);
|
||||
}
|
||||
}, [api, isConnected, ip, isDemoMode, fetchState, fetchPeqState]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user