mirror of
https://github.com/RSS-Bridge/rss-bridge.git
synced 2025-03-14 20:21:14 +03:00
feat: improve http 429 handling (#3541)
This commit is contained in:
parent
773eea196f
commit
310160fd92
3 changed files with 8 additions and 8 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]);
|
||||
}
|
||||
|
|
|
@ -197,7 +197,7 @@ function getContents(
|
|||
}
|
||||
}
|
||||
|
||||
throw new HttpException($exceptionMessage, $result['code']);
|
||||
throw new HttpException(trim($exceptionMessage), $result['code']);
|
||||
}
|
||||
if ($returnFull === true) {
|
||||
return $response;
|
||||
|
|
Loading…
Add table
Reference in a new issue