Skip to content

Commit

Permalink
tweak: Report exceptions raised under GTFS import endpoints for easie…
Browse files Browse the repository at this point in the history
…r debugging in gtfs_creator CI (#1023)
  • Loading branch information
jzimbel-mbta authored Oct 31, 2024
1 parent 88495a7 commit 414abeb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lib/arrow_web/controllers/api/gtfs_import_controller.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
defmodule ArrowWeb.API.GtfsImportController do
use ArrowWeb, :controller

use Plug.ErrorHandler

require Logger
import Ecto.Query

Expand Down Expand Up @@ -94,6 +96,21 @@ defmodule ArrowWeb.API.GtfsImportController do
check_jobs(conn, %{"status_filter" => "all"})
end

# Since all of this controller's endpoints are expected to be used exclusively
# by developers, in CI workflows, with authentication, we can send specific
# error info back so that it doesn't have to be hunted down separately in
# splunk. (It will still be logged to splunk as well, though.)
@impl Plug.ErrorHandler
def handle_errors(conn, %{reason: error}) when is_exception(error) do
send_resp(conn, conn.status, Exception.message(error))
end

def handle_errors(conn, error_info) do
# A throw or an exit--unlikely to happen.
details = Exception.format(error_info.kind, error_info.reason, error_info.stack)
send_resp(conn, conn.status, "Arrow encountered a problem:\n#{details}")
end

@spec to_resp({:ok, term} | error_tuple, Plug.Conn.t()) :: Plug.Conn.t()
defp to_resp(result, conn) do
case result do
Expand Down

0 comments on commit 414abeb

Please sign in to comment.