mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-09 22:57:21 +00:00
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:
@ -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>?;
|
||||
|
Reference in New Issue
Block a user