diff --git a/src/FACT_road.jl b/src/FACT_road.jl index e850f9f77afd25a630fdd0aa7577ab5d680e70bf..9e6e42b3e69dee591c69c2b244ab41c7268e0f1c 100644 --- a/src/FACT_road.jl +++ b/src/FACT_road.jl @@ -28,17 +28,6 @@ function travel_time_in_minutes(ws_host_port::String, selection::Dict) geo_id = selection["geo_id"] shape_obj = selection["shape_obj"] - # filter out Hawaii - # Convert geo_id to integers - geo_id_int = parse.(Int, geo_id) - - # Apply the range condition - condition = (geo_id_int .>= 15000) .& (geo_id_int .< 16000) - - # Overwrite the original arrays with the filtered results - geo_id = geo_id[.!condition] - shape_obj = shape_obj[.!condition] - # Arrays to store column data o_geo_ids = String[] d_geo_ids = String[] @@ -59,13 +48,23 @@ function travel_time_in_minutes(ws_host_port::String, selection::Dict) # Construct the request URL url = "$ws_host_port/route/v1/driving/$(start_longitude),$(start_latitude);$(end_longitude),$(end_latitude)?overview=false" - # Make the request - response = HTTP.get(url) - # Parse the response - data = JSON.parse(String(response.body)) - # Extract and calculate travel time in minutes - travel_time_seconds = data["routes"][1]["duration"] - travel_time = travel_time_seconds / 60 + + try + # Make the request + response = HTTP.get(url) + # Ensure the response status code is 200 (OK) + if response.status != 200 + throw(Exception("Request failed with status code $(response.status)")) + end + # Parse the response + data = JSON.parse(String(response.body)) + # Extract and calculate travel time in minutes + travel_time_seconds = data["routes"][1]["duration"] + travel_time = travel_time_seconds / 60 + catch e + println("Error during HTTP request or response parsing: ", e) + travel_time = nothing # Use `nothing` to represent null in Julia + end # Populate the columns push!(o_geo_ids, geo_id[i])