From 88766e6fdeb12c1ca67e21c922c016d1d8ca3178 Mon Sep 17 00:00:00 2001 From: Dag Date: Fri, 18 Nov 2022 21:36:06 +0100 Subject: [PATCH] fix: produce smaller log records for http exceptions (#3153) --- actions/DisplayAction.php | 9 ++++++++- lib/utils.php | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index a0b23fd0..58aaa0d0 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -152,7 +152,14 @@ class DisplayAction implements ActionInterface 'icon' => $bridge->getIcon() ]; } catch (\Throwable $e) { - Logger::error(sprintf('Exception in %s', $bridgeClassName), ['e' => $e]); + if ($e instanceof HttpException) { + // Produce a smaller log record for http exceptions + Logger::warning(sprintf('Exception in %s: %s', $bridgeClassName, create_sane_exception_message($e))); + } else { + // Log the exception + Logger::error(sprintf('Exception in %s', $bridgeClassName), ['e' => $e]); + } + $errorCount = logBridgeError($bridge::NAME, $e->getCode()); if ($errorCount >= Configuration::getConfig('error', 'report_limit')) { diff --git a/lib/utils.php b/lib/utils.php index 0d23c74b..41858a09 100644 --- a/lib/utils.php +++ b/lib/utils.php @@ -48,7 +48,7 @@ function get_current_url(): string function create_sane_exception_message(\Throwable $e): string { return sprintf( - 'Exception %s: %s in %s line %s', + '%s: %s in %s line %s', get_class($e), $e->getMessage(), trim_path_prefix($e->getFile()),