feat: complete centralized error handling system with documentation
This commit is contained in:
@@ -24,11 +24,17 @@ mixin DataErrorHandler {
|
||||
} on SocketException catch (e) {
|
||||
throw NetworkException(technicalMessage: 'SocketException: ${e.message}');
|
||||
} on FirebaseException catch (e) {
|
||||
if (e.code == 'unavailable' || e.code == 'network-request-failed') {
|
||||
final String code = e.code.toLowerCase();
|
||||
final String msg = (e.message ?? '').toLowerCase();
|
||||
if (code == 'unavailable' ||
|
||||
code == 'network-request-failed' ||
|
||||
msg.contains('offline') ||
|
||||
msg.contains('network') ||
|
||||
msg.contains('connection failed')) {
|
||||
throw NetworkException(
|
||||
technicalMessage: 'Firebase ${e.code}: ${e.message}');
|
||||
}
|
||||
if (e.code == 'deadline-exceeded') {
|
||||
if (code == 'deadline-exceeded') {
|
||||
throw ServiceUnavailableException(
|
||||
technicalMessage: 'Firebase ${e.code}: ${e.message}');
|
||||
}
|
||||
@@ -36,8 +42,28 @@ mixin DataErrorHandler {
|
||||
throw ServerException(
|
||||
technicalMessage: 'Firebase ${e.code}: ${e.message}');
|
||||
} catch (e) {
|
||||
final String errorStr = e.toString().toLowerCase();
|
||||
if (errorStr.contains('socketexception') ||
|
||||
errorStr.contains('network') ||
|
||||
errorStr.contains('offline') ||
|
||||
errorStr.contains('connection failed') ||
|
||||
errorStr.contains('unavailable') ||
|
||||
errorStr.contains('handshake') ||
|
||||
errorStr.contains('clientexception') ||
|
||||
errorStr.contains('failed host lookup') ||
|
||||
errorStr.contains('connection error') ||
|
||||
errorStr.contains('grpc error') ||
|
||||
errorStr.contains('terminated') ||
|
||||
errorStr.contains('connectexception')) {
|
||||
throw NetworkException(technicalMessage: e.toString());
|
||||
}
|
||||
|
||||
// If it's already an AppException, rethrow it
|
||||
if (e is AppException) rethrow;
|
||||
|
||||
// Debugging: Log unexpected errors
|
||||
print('DataErrorHandler: Unhandled exception caught: $e');
|
||||
|
||||
throw UnknownException(technicalMessage: e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user