31 lines
923 B
Dart
31 lines
923 B
Dart
import 'package:dio/dio.dart';
|
|
import 'package:wallpaperx/common/utils/log_print.dart';
|
|
|
|
class Http {
|
|
Dio dio = Dio(BaseOptions(
|
|
connectTimeout: const Duration(milliseconds: 40000),
|
|
receiveTimeout: const Duration(milliseconds: 40000),
|
|
sendTimeout: const Duration(milliseconds: 40000),
|
|
));
|
|
|
|
Http() {
|
|
dio.interceptors.add(
|
|
InterceptorsWrapper(
|
|
onRequest: (RequestOptions options, RequestInterceptorHandler handler) {
|
|
return handler.next(options);
|
|
},
|
|
onResponse:
|
|
(Response response, ResponseInterceptorHandler handler) async {
|
|
return handler.next(response);
|
|
},
|
|
onError: (DioException e, ErrorInterceptorHandler handler) async {
|
|
if (e.response?.data is String) {
|
|
return handler.reject(e);
|
|
} else if (e.response?.data is Map) {}
|
|
return handler.next(e);
|
|
},
|
|
),
|
|
);
|
|
}
|
|
}
|