better errorhandling, slimmed down optimizer
This commit is contained in:
		| @@ -11,9 +11,11 @@ import "package:anyway/structs/preferences.dart"; | ||||
| Dio dio = Dio( | ||||
|     BaseOptions( | ||||
|       baseUrl: API_URL_BASE, | ||||
|       // baseUrl: 'http://localhost:8000', | ||||
|       connectTimeout: const Duration(seconds: 5), | ||||
|       receiveTimeout: const Duration(seconds: 120), | ||||
|       // also accept 500 errors, since we cannot rule out that the server is at fault. We still want to gracefully handle these errors | ||||
|       validateStatus: (status) => status! <= 500, | ||||
|       receiveDataWhenStatusError: true, | ||||
|       // api is notoriously slow | ||||
|       // headers: { | ||||
|       //   HttpHeaders.userAgentHeader: 'dio', | ||||
| @@ -45,24 +47,20 @@ fetchTrip( | ||||
|   // handle errors | ||||
|   if (response.statusCode != 200) { | ||||
|     trip.updateUUID("error"); | ||||
|     throw Exception('Failed to load trip'); | ||||
|   } | ||||
|   if (response.data["error"] != null) { | ||||
|     trip.updateUUID("error"); | ||||
|     throw Exception(response.data["error"]); | ||||
|     if (response.data["detail"] != null) { | ||||
|       trip.updateError(response.data["detail"]); | ||||
|       // throw Exception(response.data["detail"]); | ||||
|     } | ||||
|   } | ||||
|  | ||||
|   log(response.data.toString()); | ||||
|   Map<String, dynamic> json = response.data; | ||||
|  | ||||
|   // only fill in the trip "meta" data for now | ||||
|   trip.loadFromJson(json); | ||||
|  | ||||
|  | ||||
|   // now fill the trip with landmarks | ||||
|   // if (trip.landmarks.isNotEmpty) { | ||||
|   //   trip.landmarks.clear(); | ||||
|   // } | ||||
|   // we are going to recreate all the landmarks from the information given by the api | ||||
|   // we are going to recreate ALL the landmarks from the information given by the api | ||||
|   trip.landmarks.remove(trip.landmarks.first); | ||||
|   String? nextUUID = json["first_landmark_uuid"]; | ||||
|   while (nextUUID != null) { | ||||
| @@ -83,8 +81,8 @@ Future<(Landmark, String?)> fetchLandmark(String uuid) async { | ||||
|   if (response.statusCode != 200) { | ||||
|     throw Exception('Failed to load landmark'); | ||||
|   } | ||||
|   if (response.data["error"] != null) { | ||||
|     throw Exception(response.data["error"]); | ||||
|   if (response.data["detail"] != null) { | ||||
|     throw Exception(response.data["detail"]); | ||||
|   } | ||||
|   log(response.data.toString()); | ||||
|   Map<String, dynamic> json = response.data; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user