fix(mobile): ios random logout (#8997)

* fix(mobile): random logout

* move logout mechanism to the end

* More logs

* wording

* more logs

* fixed

* Better check
This commit is contained in:
Alex 2024-04-23 16:09:10 -05:00 committed by GitHub
parent 70c78a09a4
commit 48b0b7e8bd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 70 additions and 25 deletions

View file

@ -5,6 +5,7 @@ import 'dart:io';
import 'package:flutter/material.dart';
import 'package:immich_mobile/shared/models/store.dart';
import 'package:immich_mobile/utils/url_helper.dart';
import 'package:logging/logging.dart';
import 'package:openapi/api.dart';
import 'package:http/http.dart';
@ -34,6 +35,7 @@ class ApiService {
}
}
String? _accessToken;
final _log = Logger("ApiService");
setEndpoint(String endpoint) {
_apiClient = ApiClient(basePath: endpoint);
@ -95,14 +97,17 @@ class ApiService {
serverUrl += '/api';
}
// Throw Socket or Timeout exceptions,
// we do not care if the endpoints hits an HTTP error
try {
await client
.get(
Uri.parse(serverUrl),
)
final response = await client
.get(Uri.parse("$serverUrl/server-info/ping"))
.timeout(const Duration(seconds: 5));
if (response.statusCode != 200) {
_log.severe(
"Server Gateway Error: ${response.body} - Cannot communicate to the server",
);
return false;
}
} on TimeoutException catch (_) {
return false;
} on SocketException catch (_) {