Skip to content

Commit

Permalink
feat(Live.TripPlanner): handle OTP timeouts (#2364)
Browse files Browse the repository at this point in the history
  • Loading branch information
thecristen authored Feb 5, 2025
1 parent a519f6e commit b28074d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
15 changes: 11 additions & 4 deletions lib/dotcom_web/live/trip_planner.ex
Original file line number Diff line number Diff line change
Expand Up @@ -116,21 +116,28 @@ defmodule DotcomWeb.Live.TripPlanner do
end

@impl true
# Triggered when we cannot connect to OTP.
# Triggered when we cannot connect to OTP, or we receive a timeout error.
def handle_async(
"get_itinerary_groups",
{:ok, {:error, %Req.TransportError{reason: :econnrefused}}},
{:ok, {:error, %Req.TransportError{reason: _reason}}},
socket
) do
message = "Cannot connect to OpenTripPlanner. Please try again later."
message =
Application.get_env(
:open_trip_planner_client,
:fallback_error_message,
"Cannot connect to OpenTripPlanner. Please try again later."
)

new_socket = assign(socket, :results, Map.put(@state.results, :error, message))

{:noreply, new_socket}
end

@impl true
# Triggered by OTP errors, we combine them into a single error message and add it to the results state.
def handle_async("get_itinerary_groups", {:ok, {:error, errors}}, socket) do
def handle_async("get_itinerary_groups", {:ok, {:error, errors}}, socket)
when is_list(errors) do
error =
errors
|> Enum.map_join(", ", &Map.get(&1, :message))
Expand Down
6 changes: 5 additions & 1 deletion test/dotcom_web/live/trip_planner_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,11 @@ defmodule DotcomWeb.Live.TripPlannerTest do

document = render_async(view)

assert document =~ "Cannot connect to OpenTripPlanner. Please try again later."
assert document =~
Application.get_env(
:open_trip_planner_client,
:fallback_error_message
)
end

test "an OTP error shows up as an error message", %{view: view} do
Expand Down

0 comments on commit b28074d

Please sign in to comment.