some fixes
This commit is contained in:
@@ -2,6 +2,7 @@ import 'dart:io';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
import 'package:tm_app/data/services/model/error/error_model.dart';
|
||||
import 'package:tm_app/data/services/model/login_response/login_response_model.dart';
|
||||
|
||||
import '../config/app_config.dart';
|
||||
@@ -305,15 +306,24 @@ class NetworkManager {
|
||||
return 'Unknown error';
|
||||
}
|
||||
|
||||
if (data is Map<String, dynamic>) {
|
||||
return data['message'] ??
|
||||
data['error'] ??
|
||||
data['detail'] ??
|
||||
'Unknown error';
|
||||
}
|
||||
try {
|
||||
if (data is Map<String, dynamic>) {
|
||||
final Object? nested = data['error'];
|
||||
final Map<String, dynamic> json =
|
||||
nested is Map<String, dynamic> ? nested : data;
|
||||
final ErrorModel model = ErrorModel.fromJson(json);
|
||||
return model.message ??
|
||||
model.details ??
|
||||
model.code ??
|
||||
(data['detail'] as String?) ??
|
||||
'Unknown error';
|
||||
}
|
||||
|
||||
if (data is String) {
|
||||
return data;
|
||||
if (data is String) {
|
||||
return data;
|
||||
}
|
||||
} catch (_) {
|
||||
// fall through to default message
|
||||
}
|
||||
|
||||
return 'Unknown error';
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import 'package:tm_app/core/network/app_exceptions.dart';
|
||||
|
||||
/// Utility class for handling error messages
|
||||
class ErrorUtils {
|
||||
/// Extracts a clean error message from an Exception
|
||||
static String getErrorMessage(Exception error) {
|
||||
if (error is AppException) {
|
||||
return error.message;
|
||||
}
|
||||
|
||||
// For plain Exception, remove "Exception: " prefix
|
||||
final errorString = error.toString();
|
||||
if (errorString.startsWith('Exception: ')) {
|
||||
return errorString.substring(11);
|
||||
}
|
||||
|
||||
return errorString;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user