diff --git a/app/utils/network.js b/app/utils/network.js index 09b852bb0..a84316450 100644 --- a/app/utils/network.js +++ b/app/utils/network.js @@ -2,12 +2,17 @@ import {NetInfo} from 'react-native'; import {Client4} from 'mattermost-redux/client'; -export async function checkConnection() { +export async function checkConnection(isConnected) { + if (Client4.getBaseRoute() === '/api/v4') { + // If we don't have a server yet, return the default implementation + return isConnected; + } + // Ping the Mattermost server to detect if the we have network connection even if the websocket cannot connect const server = `${Client4.getBaseRoute()}/system/ping?time=${Date.now()}`; try { - await fetch(server); + await fetch(server, {method: 'get'}); return true; } catch (error) { return false; @@ -15,8 +20,8 @@ export async function checkConnection() { } function handleConnectionChange(onChange) { - return async () => { - const result = await checkConnection(); + return async (isConnected) => { + const result = await checkConnection(isConnected); onChange(result); }; }