feat: improve http 429 handling (#3541)

This commit is contained in:
Dag 2023-07-16 07:18:38 +02:00 committed by GitHub
parent 773eea196f
commit 310160fd92
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 8 deletions

View File

@ -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;
}
}

View File

@ -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]);
}

View File

@ -197,7 +197,7 @@ function getContents(
}
}
throw new HttpException($exceptionMessage, $result['code']);
throw new HttpException(trim($exceptionMessage), $result['code']);
}
if ($returnFull === true) {
return $response;