Skip to content

Commit

Permalink
Add a new log fn for unrecognized triptych player name (#1844)
Browse files Browse the repository at this point in the history
  • Loading branch information
jzimbel-mbta authored Aug 31, 2023
1 parent 6f5753f commit 52cc71a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 12 deletions.
4 changes: 4 additions & 0 deletions lib/screens/log_screen_data.ex
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ defmodule Screens.LogScreenData do
log_message("[screen frontend error]", data)
end

def log_unrecognized_triptych_player(player_name) do
log_message("[unrecognized triptych player name]", %{player_name: player_name})
end

def log_api_response(response, screen_id, last_refresh, is_screen, screen_side \\ nil)

def log_api_response(
Expand Down
30 changes: 18 additions & 12 deletions lib/screens_web/controllers/v2/screen_api_controller.ex
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
use ScreensWeb, :controller

alias Screens.Config.State
alias Screens.LogScreenData
alias Screens.Util
alias Screens.V2.ScreenData

Expand All @@ -25,7 +26,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
triptych_pane = params["pane"]
ofm_app_package_version = params["version"]

Screens.LogScreenData.log_data_request(
LogScreenData.log_data_request(
screen_id,
last_refresh,
is_screen,
Expand All @@ -38,7 +39,7 @@ defmodule ScreensWeb.V2.ScreenApiController do

cond do
nonexistent_screen?(screen_id) ->
Screens.LogScreenData.log_api_response(
LogScreenData.log_api_response(
:nonexistent,
screen_id,
last_refresh,
Expand All @@ -49,7 +50,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
not_found_response(conn)

Util.outdated?(screen_id, last_refresh) ->
Screens.LogScreenData.log_api_response(
LogScreenData.log_api_response(
:outdated,
screen_id,
last_refresh,
Expand All @@ -60,7 +61,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
json(conn, ScreenData.outdated_response())

disabled?(screen_id) ->
Screens.LogScreenData.log_api_response(
LogScreenData.log_api_response(
:disabled,
screen_id,
last_refresh,
Expand All @@ -71,7 +72,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
json(conn, ScreenData.disabled_response())

true ->
Screens.LogScreenData.log_api_response(
LogScreenData.log_api_response(
:success,
screen_id,
last_refresh,
Expand All @@ -87,16 +88,21 @@ defmodule ScreensWeb.V2.ScreenApiController do

def show_triptych(conn, %{"player_name" => player_name} = params) do
case Screens.TriptychPlayer.fetch_screen_id_for_player(player_name) do
{:ok, screen_id} -> show(conn, Map.put(params, "id", screen_id))
# Reuse the logic + logging in show/2 for nonexistent IDs.
# This will log a data request for triptych_player_name:#{player_name} and
# Return a 404 response.
:error -> show(conn, Map.put(params, "id", "triptych_player_name:#{player_name}"))
{:ok, screen_id} ->
show(conn, Map.put(params, "id", screen_id))

:error ->
LogScreenData.log_unrecognized_triptych_player(player_name)

# Reuse the logic + logging in show/2 for nonexistent IDs.
# This will log a data request for the nonexistent player name and
# return a 404 response.
show(conn, Map.put(params, "id", "triptych_player_name--#{player_name}"))
end
end

def simulation(conn, %{"id" => screen_id, "last_refresh" => last_refresh} = params) do
Screens.LogScreenData.log_data_request(
LogScreenData.log_data_request(
screen_id,
last_refresh,
false,
Expand Down Expand Up @@ -124,7 +130,7 @@ defmodule ScreensWeb.V2.ScreenApiController do
"errorMessage" => error_message,
"stacktrace" => stack_trace
}) do
Screens.LogScreenData.log_frontend_error(screen_id, error_message, stack_trace)
LogScreenData.log_frontend_error(screen_id, error_message, stack_trace)
json(conn, %{success: true})
end

Expand Down

0 comments on commit 52cc71a

Please sign in to comment.