handleError static method
Implementation
static Future<void> handleError(Object e) async {
if (e is DioException) {
if (e.response?.statusCode == 401) {
if (UFUtils.refreshToken != null) {
await UFUtils.refreshToken?.call();
if (UFUtils.refreshDestination.isNotEmpty) {
Get.offAndToNamed(UFUtils.refreshDestination);
}
}
return;
}
debugPrint('🔴 🔴 🔴 🔴 DioException caught! 🔴 🔴 🔴 🔴 ');
debugPrint('Request Path: ${e.requestOptions.path}');
debugPrint('Type: ${e.type}');
debugPrint('Status Code: ${e.response?.statusCode}');
debugPrint('Data: ${e.response?.data}');
debugPrint('Message: ${e.message}');
debugPrint('🔴 🔴 🔴 🔴 🔴 🔴 🔴 🔴 ');
return;
} else {
String? user = await UFUtils.preferences.readObject(
UFUtils.preferences.userData,
);
Map<String, dynamic>? userJson = user != null ? jsonDecode(user) : null;
List<String> information = [];
information.add("user_id: ${userJson?['_id']?.toString()}");
information.add("screen: ${Get.currentRoute}");
information.add("app_version: ${UFUtils.appVersion}");
FirebaseCrashlytics.instance.recordError(
e,
StackTrace.current,
fatal: false,
information: information,
);
return;
}
}