Slide 13
Slide 13 text
Future> getHotels() async {
try {
final data = await http.get(_baseUrl + _endPoint);
final responseList = json.decode(data.body);
return [for (final hotel in responseList)
HotelModel.fromJson(hotel)];
} on SocketException {
throw Failure("No internet connection", 400);
} on HttpException {
throw Failure("Not found request", 404);
} on FormatException {
throw Failure("Invalid JSON format", 666);
} catch (e) {
throw Failure("Unknown error", 888);
}
}