aaa
This commit is contained in:
@@ -89,21 +89,31 @@ class AuthRemoteDataSourceImpl implements AuthRemoteDataSource {
|
||||
@override
|
||||
Future<UserModel> getProfile() async {
|
||||
try {
|
||||
print('📡 DataSource: Calling getProfile API...');
|
||||
final response = await dioClient.get(ApiConstants.profile);
|
||||
|
||||
print('📡 DataSource: Profile status=${response.statusCode}');
|
||||
print('📡 DataSource: Profile response keys=${response.data?.keys?.toList()}');
|
||||
print('📡 DataSource: Profile response=$response.data}');
|
||||
|
||||
if (response.statusCode == ApiConstants.statusOk) {
|
||||
// API might return nested structure: {success, data: user, message}
|
||||
// Check if response has 'data' key
|
||||
final userData = response.data['data'] != null
|
||||
? response.data['data'] as Map<String, dynamic>
|
||||
: response.data as Map<String, dynamic>;
|
||||
return UserModel.fromJson(userData);
|
||||
// API returns nested structure: {success, data: user, message}
|
||||
// Extract the 'data' object
|
||||
final userData = response.data['data'] as Map<String, dynamic>;
|
||||
print('📡 DataSource: Extracted user data with keys=${userData.keys.toList()}');
|
||||
|
||||
final userModel = UserModel.fromJson(userData);
|
||||
print('📡 DataSource: User parsed successfully: ${userModel.name}');
|
||||
return userModel;
|
||||
} else {
|
||||
throw ServerException('Get profile failed with status: ${response.statusCode}');
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
print('❌ DataSource: Profile DioException - ${e.message}');
|
||||
throw _handleDioError(e);
|
||||
} catch (e) {
|
||||
} catch (e, stackTrace) {
|
||||
print('❌ DataSource: Profile unexpected error - $e');
|
||||
print('Stack trace: $stackTrace');
|
||||
throw ServerException('Unexpected error getting profile: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user