Skip to content

Commit

Permalink
tweak: Log URL for failed V3 API requests (#1875)
Browse files Browse the repository at this point in the history
* Log URL for failed V3 API requests

* Make url a required param
  • Loading branch information
jzimbel-mbta authored Sep 28, 2023
1 parent 1dfe895 commit 0137ce2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/screens/v3_api.ex
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,30 @@ defmodule Screens.V3Api do
else
{:http_request, e} ->
{:error, httpoison_error} = e
log_api_error({:http_fetch_error, e}, message: Exception.message(httpoison_error))

log_api_error({:http_fetch_error, e}, url, message: Exception.message(httpoison_error))

{:response_success, %{status_code: 304}} ->
:not_modified

{:response_success, %{status_code: status_code}} = response ->
_ = log_api_error({:bad_response_code, response}, status_code: status_code)
_ = log_api_error({:bad_response_code, response}, url, status_code: status_code)

:bad_response_code

{:parse, {:error, e}} ->
log_api_error({:parse_error, e})
log_api_error({:parse_error, e}, url)

e ->
log_api_error({:error, e})
log_api_error({:error, e}, url)
end
end

defp log_api_error({error_type, _error_data} = error, extra_fields \\ []) do
defp log_api_error({error_type, _error_data} = error, url, extra_fields \\ []) do
extra_fields
|> Enum.map_join(" ", fn {label, value} -> "#{label}=\"#{value}\"" end)
|> then(fn fields ->
Logger.info("[api_v3_get_json_error] error_type=#{error_type} " <> fields)
Logger.info("[api_v3_get_json_error] url=\"#{url}\" error_type=#{error_type} " <> fields)
end)

error
Expand Down

0 comments on commit 0137ce2

Please sign in to comment.