You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.4 KiB

import 'package:cloud_car_internal/providers/user_provider.dart';
import 'package:cloud_car_internal/utils/toast/cloud_toast.dart';
import 'package:dio/dio.dart';
import 'package:get/get.dart' hide Response;
import 'package:provider/provider.dart';
class NetworkInterceptor extends Interceptor {
@override
void onResponse(Response response, ResponseInterceptorHandler handler) async {
final userProvider = Provider.of<UserProvider>(Get.context!, listen: false);
// LoggerData.addData(response);
int code = response.data['code'] ?? 0;
switch (code) {
//登录超时
case 100000:
await userProvider.logout();
CloudToast.show(response.data['msg']);
// await Get.offAll(() => const LoginPage());
break;
default:
break;
}
super.onResponse(response, handler);
}
@override
void onError(DioError err, ErrorInterceptorHandler handler) async {
switch (err.type) {
case DioErrorType.connectTimeout:
case DioErrorType.sendTimeout:
case DioErrorType.receiveTimeout:
CloudToast.show('连接超时');
break;
case DioErrorType.response:
CloudToast.show('Server Err');
break;
case DioErrorType.cancel:
break;
case DioErrorType.other:
CloudToast.show('网络出现问题');
break;
}
super.onError(err, handler);
}
}