|
|
@ -1,5 +1,5 @@ |
|
|
import 'package:dio/dio.dart'; |
|
|
import 'package:dio/dio.dart'; |
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart'; |
|
|
import 'package:flutter/material.dart'; |
|
|
import 'package:get/get.dart' hide Response; |
|
|
import 'package:get/get.dart' hide Response; |
|
|
|
|
|
|
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
import 'package:get_storage/get_storage.dart'; |
|
|
@ -24,7 +24,14 @@ class AuthInterceptor extends Interceptor { |
|
|
} else { |
|
|
} else { |
|
|
response.data = null; |
|
|
response.data = null; |
|
|
handler.next(response); |
|
|
handler.next(response); |
|
|
return EasyLoading.showError(entity.message ?? 'unknownError'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
entity.message ?? 'unknownError'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
|
|
|
return; |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
@ -33,32 +40,74 @@ class AuthInterceptor extends Interceptor { |
|
|
switch (err.type) { |
|
|
switch (err.type) { |
|
|
case DioExceptionType.cancel: |
|
|
case DioExceptionType.cancel: |
|
|
{ |
|
|
{ |
|
|
EasyLoading.showError('requestCancellation'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
'requestCancellation'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
case DioExceptionType.connectionTimeout: |
|
|
case DioExceptionType.connectionTimeout: |
|
|
{ |
|
|
{ |
|
|
EasyLoading.showError('connectionTimeout'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
'connectionTimeout'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
case DioExceptionType.sendTimeout: |
|
|
case DioExceptionType.sendTimeout: |
|
|
{ |
|
|
{ |
|
|
EasyLoading.showError('requestTimeout'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
'requestTimeout'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
case DioExceptionType.receiveTimeout: |
|
|
case DioExceptionType.receiveTimeout: |
|
|
{ |
|
|
{ |
|
|
EasyLoading.showError('responseTimeout'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
'responseTimeout'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
case DioExceptionType.badResponse: |
|
|
case DioExceptionType.badResponse: |
|
|
{ |
|
|
{ |
|
|
try { |
|
|
try { |
|
|
String? errMsg = err.response?.statusMessage; |
|
|
String? errMsg = err.response?.statusMessage; |
|
|
EasyLoading.showError(errMsg ?? 'unknownError'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
errMsg ?? 'unknownError'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} on Exception catch (_) { |
|
|
} on Exception catch (_) { |
|
|
EasyLoading.showError('unknownError'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
'unknownError'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
default: |
|
|
default: |
|
|
{ |
|
|
{ |
|
|
EasyLoading.showError(err.message ?? 'unknownError'.tr); |
|
|
Get.snackbar( |
|
|
|
|
|
'error'.tr, // 错误 |
|
|
|
|
|
err.message ?? 'unknownError'.tr, |
|
|
|
|
|
snackPosition: SnackPosition.TOP, |
|
|
|
|
|
backgroundColor: Colors.red.withOpacity(0.1), |
|
|
|
|
|
colorText: Colors.red, |
|
|
|
|
|
); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
handler.next(err); |
|
|
handler.next(err); |
|
|
|