Don't track route not found errors

This commit is contained in:
Claudio Ortolina
2026-03-10 20:05:27 +00:00
parent fa535393e0
commit 20b497bbb8
3 changed files with 23 additions and 28 deletions
+5 -1
View File
@@ -7,7 +7,11 @@
# General application configuration
import Config
config :error_tracker, repo: MusicLibrary.Repo, otp_app: :music_library, enabled: false
config :error_tracker,
repo: MusicLibrary.Repo,
otp_app: :music_library,
enabled: false,
ignorer: MusicLibrary.ErrorIgnorer
config :elixir, :time_zone_database, TimeZoneInfo.TimeZoneDatabase
+18
View File
@@ -0,0 +1,18 @@
defmodule MusicLibrary.ErrorIgnorer do
@moduledoc """
Ignores errors that should not be tracked by ErrorTracker.
Bot scanners and crawlers routinely hit non-existent paths, generating
NoRouteError exceptions that are not actionable. We ignore them here
rather than blocking specific paths in the endpoint.
"""
@behaviour ErrorTracker.Ignorer
@ignored_kinds [
to_string(Phoenix.Router.NoRouteError)
]
@impl true
def ignore?(%ErrorTracker.Error{kind: kind}, _context) when kind in @ignored_kinds, do: true
def ignore?(_error, _context), do: false
end
-27
View File
@@ -43,8 +43,6 @@ defmodule MusicLibraryWeb.Endpoint do
plug Phoenix.Ecto.CheckRepoStatus, otp_app: :music_library
end
plug :reject_bot_scanners
plug Phoenix.LiveDashboard.RequestLogger,
param_key: "request_logger",
cookie_key: "request_logger"
@@ -61,29 +59,4 @@ defmodule MusicLibraryWeb.Endpoint do
plug Plug.Head
plug Plug.Session, @session_options
plug MusicLibraryWeb.Router
defp reject_bot_scanners(%{request_path: "/wp-" <> _} = conn, _opts),
do: conn |> send_resp(404, "") |> halt()
defp reject_bot_scanners(%{request_path: "/wordpress" <> _} = conn, _opts),
do: conn |> send_resp(404, "") |> halt()
@blocked_paths [
"/.env",
"/admin",
"/blog/wp-includes/wlwmanifest.xml",
"/files.php",
"/grsiuk.php",
"/jq.php",
"/style.php",
"/vgtyu.php",
"/vx.php",
"/xleet.php",
"/xmlrpc.php"
]
defp reject_bot_scanners(%{request_path: path} = conn, _opts) when path in @blocked_paths,
do: conn |> send_resp(404, "") |> halt()
defp reject_bot_scanners(conn, _opts), do: conn
end