Refactor RemoteDeleteSpaceService: Simplify success response handling and improve error message formatting

This commit is contained in:
Faris Armoush
2025-07-14 14:30:17 +03:00
parent 035c03c6b2
commit 086f3cedf8

View File

@ -19,8 +19,7 @@ final class RemoteDeleteSpaceService implements DeleteSpaceService {
path: await _makeUrl(param), path: await _makeUrl(param),
expectedResponseModel: (json) { expectedResponseModel: (json) {
final response = json as Map<String, dynamic>; final response = json as Map<String, dynamic>;
final data = response['data'] as Map<String, dynamic>?; final hasSuccessfullyDeletedSpace = response['success'] as bool? ?? false;
final hasSuccessfullyDeletedSpace = data?['success'] as bool? ?? false;
if (!hasSuccessfullyDeletedSpace) { if (!hasSuccessfullyDeletedSpace) {
throw APIException('Failed to delete space'); throw APIException('Failed to delete space');
@ -33,8 +32,7 @@ final class RemoteDeleteSpaceService implements DeleteSpaceService {
final message = e.response?.data as Map<String, dynamic>?; final message = e.response?.data as Map<String, dynamic>?;
throw APIException(_getErrorMessageFromBody(message)); throw APIException(_getErrorMessageFromBody(message));
} catch (e) { } catch (e) {
final formattedErrorMessage = ['Failed to delete space', '$e'].join(': '); throw APIException(e.toString());
throw APIException(formattedErrorMessage);
} }
} }