hwhub/lib/utils/error_utils.dart

37 lines
974 B
Dart

import 'package:flutter/foundation.dart';
import 'package:supabase_flutter/supabase_flutter.dart';
String userMessageForError(
Object error, {
String fallback = 'Something went wrong. Please try again.',
}) {
if (error is AuthException) {
return error.message;
}
final raw = error.toString();
final normalized = raw.toLowerCase();
if (normalized.contains('socket') ||
normalized.contains('network') ||
normalized.contains('timeout')) {
return 'Network issue. Please check your connection and try again.';
}
if (normalized.contains('permission') || normalized.contains('not allowed')) {
return 'You do not have permission for this action.';
}
if (normalized.contains('signed in')) {
return 'Please sign in again and retry.';
}
return fallback;
}
void logError(String scope, Object error, [StackTrace? stackTrace]) {
debugPrint('[$scope] $error');
if (stackTrace != null) {
debugPrint('$stackTrace');
}
}