Refactor RemoteUpdateSpaceService: Improved error handling in updateSpace method by checking API response success before returning the updated space. This enhances robustness and ensures proper error propagation for failed updates.

This commit is contained in:
Faris Armoush
2025-07-08 12:20:10 +03:00
parent bcf62027bc
commit 7c2aed2d58

View File

@ -17,19 +17,20 @@ class RemoteUpdateSpaceService implements UpdateSpaceService {
Future<SpaceDetailsModel> updateSpace(UpdateSpaceParam param) async {
try {
final path = await _makeUrl(param);
final response = await _httpService.put(
await _httpService.put(
path: path,
body: param.space.toJson(),
expectedResponseModel: (data) {
final response = data as Map<String, dynamic>;
final space = SpaceDetailsModel.fromJson(
response['data'] as Map<String, dynamic>,
);
return space;
final isSuccess = response['success'] as bool;
if (!isSuccess) {
throw APIException(response['error'] as String);
}
return isSuccess;
},
);
return response;
return param.space;
} on DioException catch (e) {
final message = e.response?.data as Map<String, dynamic>?;
final error = message?['error'] as Map<String, dynamic>?;