Update: 2026-08-06 18:32:03
This commit is contained in:
@@ -20,6 +20,37 @@ class AuthController extends GetxController {
|
||||
var isLoading = false.obs;
|
||||
var phone = ''.obs;
|
||||
|
||||
/// Turns a DioException into a message that reflects what actually failed.
|
||||
///
|
||||
/// Without this, any transport failure (expired TLS cert, no network, DNS)
|
||||
/// surfaced as "wrong credentials", which sent users hunting for a password
|
||||
/// problem that did not exist.
|
||||
String _describeDioError(DioException e,
|
||||
{String fallback = 'بيانات الدخول غير صحيحة'}) {
|
||||
final data = e.response?.data;
|
||||
if (data is Map && data['message'] != null) {
|
||||
return data['message'].toString();
|
||||
}
|
||||
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
case DioExceptionType.sendTimeout:
|
||||
case DioExceptionType.receiveTimeout:
|
||||
return 'انتهت مهلة الاتصال بالخادم. تحقق من اتصالك بالإنترنت.';
|
||||
case DioExceptionType.badCertificate:
|
||||
return 'تعذّر التحقق من شهادة أمان الخادم. يرجى التواصل مع الدعم.';
|
||||
case DioExceptionType.connectionError:
|
||||
case DioExceptionType.unknown:
|
||||
final msg = e.error?.toString() ?? e.message ?? '';
|
||||
if (msg.contains('CERTIFICATE') || msg.contains('HandshakeException')) {
|
||||
return 'تعذّر التحقق من شهادة أمان الخادم. يرجى التواصل مع الدعم.';
|
||||
}
|
||||
return 'تعذّر الاتصال بالخادم. تحقق من اتصالك بالإنترنت.';
|
||||
default:
|
||||
return fallback;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestOtp(String phoneNumber) async {
|
||||
try {
|
||||
if (phoneNumber.trim().isEmpty) {
|
||||
@@ -120,9 +151,9 @@ class AuthController extends GetxController {
|
||||
}
|
||||
}
|
||||
} on DioException catch (e, stackTrace) {
|
||||
AppLogger.error('OTP Verify Failed', e.response?.data, stackTrace);
|
||||
AppLogger.error('OTP Verify Failed', e.response?.data ?? e.message, stackTrace);
|
||||
AppSnackbar.showError(
|
||||
'خطأ', e.response?.data['message'] ?? 'رمز التحقق غير صحيح');
|
||||
'خطأ', _describeDioError(e, fallback: 'رمز التحقق غير صحيح'));
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
@@ -199,12 +230,8 @@ class AuthController extends GetxController {
|
||||
}
|
||||
}
|
||||
} on DioException catch (e, stackTrace) {
|
||||
AppLogger.error('Email Login Failed', e.response?.data, stackTrace);
|
||||
String errorMessage = 'بيانات الدخول غير صحيحة';
|
||||
if (e.response?.data != null && e.response?.data is Map) {
|
||||
errorMessage = e.response?.data['message'] ?? errorMessage;
|
||||
}
|
||||
AppSnackbar.showError('خطأ', errorMessage);
|
||||
AppLogger.error('Email Login Failed', e.response?.data ?? e.message, stackTrace);
|
||||
AppSnackbar.showError('خطأ', _describeDioError(e));
|
||||
} finally {
|
||||
isLoading.value = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user