mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-15 17:47:28 +00:00
Refactor API error handling and add try-catch blocks
Added try-catch blocks for error handling in API's files to rethrow the errors to the cubit so cubits can update the UI based on them. Refactored error handling in HTTPInterceptor and HTTPService classes.
This commit is contained in:
@ -125,14 +125,17 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
emitSafe(GetSpacesLoading());
|
||||
try {
|
||||
spaces = await SpacesAPI.getSpaces();
|
||||
selectedSpace = spaces!.isNotEmpty
|
||||
?
|
||||
// selectSpace(spaces!.first)
|
||||
selectedSpace = spaces!.first
|
||||
: null;
|
||||
emitSafe(GetSpacesLoaded(spaces!));
|
||||
} on ServerFailure catch (failure) {
|
||||
emitSafe(GetSpacesError(failure.errMessage));
|
||||
} catch (failure) {
|
||||
emitSafe(GetSpacesError(failure.toString()));
|
||||
return;
|
||||
}
|
||||
|
||||
if (spaces != null && spaces!.isNotEmpty) {
|
||||
selectedSpace = spaces!.first;
|
||||
emitSafe(GetSpacesSuccess(spaces!));
|
||||
fetchRooms(selectedSpace!);
|
||||
} else {
|
||||
emitSafe(GetSpacesError("No spaces found"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,13 +143,14 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
emitSafe(GetSpaceRoomsLoading());
|
||||
try {
|
||||
space.rooms = await SpacesAPI.getRoomsBySpaceId(space.id!);
|
||||
if (space.rooms != null) {
|
||||
emitSafe(GetSpaceRoomsLoaded(space.rooms!));
|
||||
} else {
|
||||
emitSafe(GetSpaceRoomsError("No rooms found"));
|
||||
}
|
||||
} on ServerFailure catch (failure) {
|
||||
emitSafe(GetSpacesError(failure.errMessage));
|
||||
} catch (failure) {
|
||||
emitSafe(GetSpaceRoomsError(failure.toString()));
|
||||
return;
|
||||
}
|
||||
if (space.rooms != null) {
|
||||
emitSafe(GetSpaceRoomsSuccess(space.rooms!));
|
||||
} else {
|
||||
emitSafe(GetSpaceRoomsError("No rooms found"));
|
||||
}
|
||||
}
|
||||
|
||||
@ -169,14 +173,6 @@ class HomeCubit extends Cubit<HomeState> {
|
||||
),
|
||||
],
|
||||
'Devices': [
|
||||
// IconButton(
|
||||
// icon: Image.asset(
|
||||
// Assets.iconsFilter,
|
||||
// height: 20,
|
||||
// width: 20,
|
||||
// ),
|
||||
// onPressed: () {},
|
||||
// ),
|
||||
IconButton(
|
||||
icon: const Icon(
|
||||
Icons.add,
|
||||
|
Reference in New Issue
Block a user