mirror of
https://github.com/SyncrowIOT/web.git
synced 2025-07-15 17:47:53 +00:00
Refactor RemoteDeleteSpaceService: Simplify success response handling and improve error message formatting
This commit is contained in:
@ -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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user