mirror of
https://github.com/SyncrowIOT/syncrow-app.git
synced 2025-07-11 15:47:35 +00:00

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.
51 lines
1.6 KiB
Dart
51 lines
1.6 KiB
Dart
import 'package:flutter_secure_storage/flutter_secure_storage.dart';
|
|
import 'package:syncrow_app/features/app_layout/model/space_model.dart';
|
|
import 'package:syncrow_app/features/auth/model/user_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/device_model.dart';
|
|
import 'package:syncrow_app/features/devices/model/room_model.dart';
|
|
import 'package:syncrow_app/services/api/api_links_endpoints.dart';
|
|
import 'package:syncrow_app/services/api/http_service.dart';
|
|
|
|
class SpacesAPI {
|
|
static final HTTPService _httpService = HTTPService();
|
|
|
|
static Future<List<SpaceModel>> getSpaces() async {
|
|
var uuid =
|
|
await const FlutterSecureStorage().read(key: UserModel.userUuidKey);
|
|
try {
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.spaces,
|
|
queryParameters: {
|
|
"userUuid": uuid,
|
|
},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) => SpaceModel.fromJsonList(json),
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
|
|
//get rooms by space id
|
|
static Future<List<RoomModel>> getRoomsBySpaceId(int spaceId) async {
|
|
try {
|
|
final response = await _httpService.get(
|
|
path: ApiEndpoints.rooms,
|
|
queryParameters: {"homeId": spaceId},
|
|
showServerMessage: false,
|
|
expectedResponseModel: (json) {
|
|
List<RoomModel> rooms = [];
|
|
for (var room in json) {
|
|
rooms.add(RoomModel.fromJson(room));
|
|
}
|
|
return rooms;
|
|
},
|
|
);
|
|
return response;
|
|
} catch (e) {
|
|
rethrow;
|
|
}
|
|
}
|
|
}
|