mirror of
https://github.com/Xevion/paperless-mobile.git
synced 2025-12-14 22:12:18 -06:00
feat: Upgrade dio version to latest, applied migrations
This commit is contained in:
@@ -22,7 +22,7 @@ class DioHttpErrorInterceptor extends Interceptor {
|
||||
DioError(
|
||||
error: const PaperlessServerException(ErrorCode.deviceOffline),
|
||||
requestOptions: err.requestOptions,
|
||||
type: DioErrorType.connectTimeout,
|
||||
type: DioErrorType.connectionTimeout,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -52,7 +52,7 @@ class DioHttpErrorInterceptor extends Interceptor {
|
||||
DioError(
|
||||
error: errorMessages,
|
||||
requestOptions: err.requestOptions,
|
||||
type: DioErrorType.response,
|
||||
type: DioErrorType.badResponse,
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -66,7 +66,7 @@ class DioHttpErrorInterceptor extends Interceptor {
|
||||
handler.reject(
|
||||
DioError(
|
||||
requestOptions: err.requestOptions,
|
||||
type: DioErrorType.response,
|
||||
type: DioErrorType.badResponse,
|
||||
error: const PaperlessServerException(
|
||||
ErrorCode.missingClientCertificate),
|
||||
),
|
||||
|
||||
@@ -28,10 +28,12 @@ class RetryOnConnectionChangeInterceptor extends Interceptor {
|
||||
}
|
||||
|
||||
bool _shouldRetryOnHttpException(DioError err) {
|
||||
return err.type == DioErrorType.other &&
|
||||
((err.error is HttpException &&
|
||||
err.message.contains(
|
||||
'Connection closed before full header was received')));
|
||||
return err.type == DioErrorType.unknown &&
|
||||
(err.error is HttpException &&
|
||||
(err.message?.contains(
|
||||
'Connection closed before full header was received',
|
||||
) ??
|
||||
false));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ class ServerReachabilityErrorInterceptor extends Interceptor {
|
||||
);
|
||||
}
|
||||
}
|
||||
if (err.type == DioErrorType.connectTimeout) {
|
||||
if (err.type == DioErrorType.connectionTimeout) {
|
||||
return _rejectWithStatus(
|
||||
ReachabilityStatus.connectionTimeout,
|
||||
err,
|
||||
@@ -55,6 +55,6 @@ void _rejectWithStatus(
|
||||
error: reachabilityStatus,
|
||||
requestOptions: err.requestOptions,
|
||||
response: err.response,
|
||||
type: DioErrorType.other,
|
||||
type: DioErrorType.unknown,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:dio/adapter.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:dio/io.dart';
|
||||
import 'package:paperless_api/paperless_api.dart';
|
||||
import 'package:paperless_mobile/core/interceptor/dio_http_error_interceptor.dart';
|
||||
import 'package:paperless_mobile/core/interceptor/retry_on_connection_change_interceptor.dart';
|
||||
import 'package:paperless_mobile/features/login/model/client_certificate.dart';
|
||||
import 'package:pretty_dio_logger/pretty_dio_logger.dart';
|
||||
@@ -20,9 +19,9 @@ class SessionManager {
|
||||
static Dio _initDio(List<Interceptor> interceptors) {
|
||||
//en- and decoded by utf8 by default
|
||||
final Dio dio = Dio(BaseOptions());
|
||||
dio.options.receiveTimeout = const Duration(seconds: 25).inMilliseconds;
|
||||
dio.options.receiveTimeout = const Duration(seconds: 25);
|
||||
dio.options.responseType = ResponseType.json;
|
||||
(dio.httpClientAdapter as DefaultHttpClientAdapter).onHttpClientCreate =
|
||||
(dio.httpClientAdapter as IOHttpClientAdapter).onHttpClientCreate =
|
||||
(client) => client..badCertificateCallback = (cert, host, port) => true;
|
||||
dio.interceptors.addAll([
|
||||
...interceptors,
|
||||
@@ -59,7 +58,7 @@ class SessionManager {
|
||||
clientCertificate.bytes,
|
||||
password: clientCertificate.passphrase,
|
||||
);
|
||||
final adapter = DefaultHttpClientAdapter()
|
||||
final adapter = IOHttpClientAdapter()
|
||||
..onHttpClientCreate = (client) => HttpClient(context: context)
|
||||
..badCertificateCallback =
|
||||
(X509Certificate cert, String host, int port) => true;
|
||||
@@ -81,7 +80,7 @@ class SessionManager {
|
||||
}
|
||||
|
||||
void resetSettings() {
|
||||
client.httpClientAdapter = DefaultHttpClientAdapter();
|
||||
client.httpClientAdapter = IOHttpClientAdapter();
|
||||
client.options.baseUrl = '';
|
||||
client.options.headers.remove('Authorization');
|
||||
serverInformation = PaperlessServerInformationModel();
|
||||
|
||||
@@ -1,8 +1,6 @@
|
||||
import 'dart:developer';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:dio/adapter.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:paperless_mobile/core/global/os_error_codes.dart';
|
||||
import 'package:paperless_mobile/core/interceptor/server_reachability_error_interceptor.dart';
|
||||
@@ -71,8 +69,8 @@ class ConnectivityStatusServiceImpl implements ConnectivityStatusService {
|
||||
SessionManager manager =
|
||||
SessionManager([ServerReachabilityErrorInterceptor()])
|
||||
..updateSettings(clientCertificate: clientCertificate)
|
||||
..client.options.connectTimeout = 5000
|
||||
..client.options.receiveTimeout = 5000;
|
||||
..client.options.connectTimeout = const Duration(seconds: 5)
|
||||
..client.options.receiveTimeout = const Duration(seconds: 5);
|
||||
|
||||
final response = await manager.client.get('$serverAddress/api/');
|
||||
if (response.statusCode == 200) {
|
||||
@@ -80,7 +78,7 @@ class ConnectivityStatusServiceImpl implements ConnectivityStatusService {
|
||||
}
|
||||
return ReachabilityStatus.notReachable;
|
||||
} on DioError catch (error) {
|
||||
if (error.type == DioErrorType.other &&
|
||||
if (error.type == DioErrorType.unknown &&
|
||||
error.error is ReachabilityStatus) {
|
||||
return error.error as ReachabilityStatus;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user