Skip to content
Snippets Groups Projects
Commit 39117aca authored by Sara Savanovic Djordjevic's avatar Sara Savanovic Djordjevic
Browse files

add: error handling for /get_lake_names

parent 35f16986
No related branches found
No related tags found
1 merge request!12Clhp map
......@@ -27,7 +27,6 @@ Future<void> initialiseState() async {
List<Measurement> measurements = fetchResult.measurements;
selectedMarkerList = measurements;
lakeSearchOptions = ["Mjøsa"];
} else { // Try to fetch measurement data from server
markerListFuture = fetchMeasurements().then((fetchResult) {
List<Measurement> measurements = fetchResult.measurements;
......@@ -84,6 +83,6 @@ Future<void> initSearchOptions() async {
}
}
} catch (e) {
lakeSearchOptions = ["Mjøsa"]; // Init default list
print("Failed to fetch lake names: $e");
}
}
\ No newline at end of file
......@@ -43,17 +43,23 @@ class IceHTTP(BaseHTTPRequestHandler):
self.wfile.write(b"Root path hit!")
elif self.path == '/get_lake_names':
with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r') as file:
lake_names = json.load(file)
try:
with open(LAKE_RELATIONS_PATH + 'all_lake_names.json', 'r') as file:
lake_names = json.load(file)
# Disable ensure_ascii to keep 'ø'
json_data = json.dumps(lake_names, ensure_ascii=False)
# Disable ensure_ascii to keep 'ø'
json_data = json.dumps(lake_names, ensure_ascii=False)
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.send_response(200)
self.send_header('Content-type', 'application/json')
self.end_headers()
self.wfile.write(json_data.encode('iso-8859-1')) # Special character encoding
self.wfile.write(json_data.encode('iso-8859-1')) # Special character encoding
except Exception as e:
print(f"Failed to fetch lake list: {e}")
self.send_response(500)
self.send_header('Content-type', 'application/json')
self.end_headers()
elif self.path.startswith('/update_map'): # NB: should be POST?
parsed_path = urlparse(self.path)
query_params = parse_qs(parsed_path.query)
......
......@@ -7,6 +7,5 @@
"Fjellsj\u00c3\u00b8en",
"Gjende",
"Gjersj\u00c3\u00b8en",
"skumsj\u00f8en",
"skumsj\u00f8en"
"Skumsj\u00c3\u00b8en"
]
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment