mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-10 15:17:31 +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 {
|
Future<SpaceDetailsModel> updateSpace(UpdateSpaceParam param) async {
|
||||||
try {
|
try {
|
||||||
final path = await _makeUrl(param);
|
final path = await _makeUrl(param);
|
||||||
final response = await _httpService.put(
|
await _httpService.put(
|
||||||
path: path,
|
path: path,
|
||||||
body: param.space.toJson(),
|
body: param.space.toJson(),
|
||||||
expectedResponseModel: (data) {
|
expectedResponseModel: (data) {
|
||||||
final response = data as Map<String, dynamic>;
|
final response = data as Map<String, dynamic>;
|
||||||
final space = SpaceDetailsModel.fromJson(
|
final isSuccess = response['success'] as bool;
|
||||||
response['data'] as Map<String, dynamic>,
|
if (!isSuccess) {
|
||||||
);
|
throw APIException(response['error'] as String);
|
||||||
return space;
|
}
|
||||||
|
return isSuccess;
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
||||||
return response;
|
return param.space;
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
final message = e.response?.data as Map<String, dynamic>?;
|
final message = e.response?.data as Map<String, dynamic>?;
|
||||||
final error = message?['error'] as Map<String, dynamic>?;
|
final error = message?['error'] as Map<String, dynamic>?;
|
||||||
|
Reference in New Issue
Block a user