From a599f4ba83b03f04a0c183c995deb24ea390e1b7 Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 8 Aug 2025 02:16:43 +0200 Subject: [PATCH] fix: dont log user errors (#4660) --- actions/DisplayAction.php | 11 +++++------ lib/utils.php | 9 ++++++++- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index 10af8ad7..97f53caa 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -89,12 +89,12 @@ class DisplayAction implements ActionInterface $bridge->collectData(); $items = $bridge->getItems(); } catch (\Throwable $e) { - if ($e instanceof RateLimitException) { - // These are internally generated by bridges - $this->logger->info(sprintf('RateLimitException in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e))); + if ($e instanceof ClientException) { + $this->logger->debug(sprintf('Exception in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e))); + } elseif ($e instanceof RateLimitException) { + $this->logger->debug(sprintf('Exception in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e))); return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 429); - } - if ($e instanceof HttpException) { + } elseif ($e instanceof HttpException) { if (in_array($e->getCode(), [429, 503])) { // Log with debug, immediately reproduce and return $this->logger->debug(sprintf('Exception in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e))); @@ -102,7 +102,6 @@ class DisplayAction implements ActionInterface } // Some other status code which we let fail normally (but don't log it) } else { - // Log error if it's not an HttpException $this->logger->error(sprintf('Exception in DisplayAction(%s)', $bridge->getShortName()), ['e' => $e]); } $errorOutput = Configuration::getConfig('error', 'output'); diff --git a/lib/utils.php b/lib/utils.php index 51e4f952..dfee437b 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -242,9 +242,16 @@ function create_random_string(int $bytes = 16): string return bin2hex(openssl_random_pseudo_bytes($bytes)); } +/** + * Thrown by bridges to indicate user failure. Will not be logged. + */ +final class ClientException extends \Exception +{ +} + function throwClientException(string $message = '') { - throw new \Exception($message, 400); + throw new ClientException($message, 400); } function throwServerException(string $message = '')