diff --git a/actions/DisplayAction.php b/actions/DisplayAction.php index 66acd4cc..91cfb95f 100644 --- a/actions/DisplayAction.php +++ b/actions/DisplayAction.php @@ -142,13 +142,14 @@ class DisplayAction implements ActionInterface 'donationUri' => $bridge->getDonationURI(), 'icon' => $bridge->getIcon() ]; - } catch (\Throwable $e) { + } catch (\Exception $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))); + Logger::warning(sprintf('Exception in DisplayAction(%s): %s', $bridgeClassName, create_sane_exception_message($e))); + if ($e->getCode() === 429) { + return new Response('503 Service Unavailable', 503); + } } else { - // Log the exception - Logger::error(sprintf('Exception in %s', $bridgeClassName), ['e' => $e]); + Logger::error(sprintf('Exception in DisplayAction(%s): %s', $bridgeClassName, create_sane_exception_message($e)), ['e' => $e]); } // Emit error only if we are passed the error report limit @@ -158,7 +159,6 @@ class DisplayAction implements ActionInterface // Emit the error as a feed item in a feed so that feed readers can pick it up $items[] = $this->createFeedItemFromException($e, $bridge); } elseif (Configuration::getConfig('error', 'output') === 'http') { - // Emit as a regular web response throw $e; } } diff --git a/lib/RssBridge.php b/lib/RssBridge.php index 79d1d710..e8b07a65 100644 --- a/lib/RssBridge.php +++ b/lib/RssBridge.php @@ -16,7 +16,7 @@ final class RssBridge try { $this->run($request); } catch (\Throwable $e) { - Logger::error('Exception in main', ['e' => $e]); + Logger::error(sprintf('Exception in RssBridge::main(): %s', create_sane_exception_message($e)), ['e' => $e]); http_response_code(500); print render(__DIR__ . '/../templates/error.html.php', ['e' => $e]); } diff --git a/lib/contents.php b/lib/contents.php index 56dd4be6..c6edba7b 100644 --- a/lib/contents.php +++ b/lib/contents.php @@ -197,7 +197,7 @@ function getContents( } } - throw new HttpException($exceptionMessage, $result['code']); + throw new HttpException(trim($exceptionMessage), $result['code']); } if ($returnFull === true) { return $response;