Skip to content

Commit

Permalink
chore(mobile): use sdk to for ping endpoint (immich-app#13218)
Browse files Browse the repository at this point in the history
  • Loading branch information
alextran1502 authored Oct 7, 2024
1 parent 4bb42c4 commit 6f86c2f
Showing 1 changed file with 2 additions and 16 deletions.
18 changes: 2 additions & 16 deletions mobile/lib/services/api.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,27 +97,13 @@ class ApiService implements Authentication {
}

Future<bool> _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 (_) {
Expand Down

0 comments on commit 6f86c2f

Please sign in to comment.