From 6f86c2f372032139434866f008dbc0761cf6a3a6 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 7 Oct 2024 08:45:23 +0700 Subject: [PATCH] chore(mobile): use sdk to for ping endpoint (#13218) --- mobile/lib/services/api.service.dart | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/mobile/lib/services/api.service.dart b/mobile/lib/services/api.service.dart index 4a3cfb19a2..515023d163 100644 --- a/mobile/lib/services/api.service.dart +++ b/mobile/lib/services/api.service.dart @@ -97,27 +97,13 @@ class ApiService implements Authentication { } Future _isEndpointAvailable(String serverUrl) async { - final Client client = Client(); - if (!serverUrl.endsWith('/api')) { serverUrl += '/api'; } try { - final response = await client - .get( - Uri.parse("$serverUrl/server-info/ping"), - headers: getRequestHeaders(), - ) - .timeout(const Duration(seconds: 5)); - - _log.info("Pinging server with response code ${response.statusCode}"); - if (response.statusCode != 200) { - _log.severe( - "Server Gateway Error: ${response.body} - Cannot communicate to the server", - ); - return false; - } + await setEndpoint(serverUrl); + await serverInfoApi.pingServer().timeout(Duration(seconds: 5)); } on TimeoutException catch (_) { return false; } on SocketException catch (_) {