1
0
mirror of https://github.com/RSS-Bridge/rss-bridge.git synced 2025-08-19 06:42:14 +02:00

feat: improve error/exception ui (#3690)

This commit is contained in:
Dag
2023-09-23 18:54:14 +02:00
committed by GitHub
parent cb6c931b1f
commit b3b0736761
9 changed files with 54 additions and 24 deletions

View File

@@ -34,7 +34,7 @@ class ConnectivityAction implements ActionInterface
public function execute(array $request)
{
if (!Debug::isEnabled()) {
return new Response('This action is only available in debug mode!');
return new Response('This action is only available in debug mode!', 403);
}
$bridgeName = $request['bridge'] ?? null;

View File

@@ -14,7 +14,10 @@ class DisplayAction implements ActionInterface
public function execute(array $request)
{
if (Configuration::getConfig('system', 'enable_maintenance_mode')) {
return new Response('503 Service Unavailable', 503);
return new Response(render(__DIR__ . '/../templates/error.html.php', [
'title' => '503 Service Unavailable',
'message' => 'RSS-Bridge is down for maintenance.',
]), 503);
}
$cacheKey = 'http_' . json_encode($request);
/** @var Response $cachedResponse */
@@ -36,19 +39,19 @@ class DisplayAction implements ActionInterface
$bridgeName = $request['bridge'] ?? null;
if (!$bridgeName) {
return new Response('Missing bridge param', 400);
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'Missing bridge parameter']), 400);
}
$bridgeFactory = new BridgeFactory();
$bridgeClassName = $bridgeFactory->createBridgeClassName($bridgeName);
if (!$bridgeClassName) {
return new Response('Bridge not found', 404);
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'Bridge not found']), 404);
}
$format = $request['format'] ?? null;
if (!$format) {
return new Response('You must specify a format!', 400);
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'You must specify a format']), 400);
}
if (!$bridgeFactory->isEnabled($bridgeClassName)) {
return new Response('This bridge is not whitelisted', 400);
return new Response(render(__DIR__ . '/../templates/error.html.php', ['message' => 'This bridge is not whitelisted']), 400);
}
$noproxy = $request['_noproxy'] ?? null;
@@ -120,11 +123,11 @@ class DisplayAction implements ActionInterface
// Reproduce (and log) these responses regardless of error output and report limit
if ($e->getCode() === 429) {
$this->logger->info(sprintf('Exception in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e)));
return new Response('429 Too Many Requests', 429);
return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 429);
}
if ($e->getCode() === 503) {
$this->logger->info(sprintf('Exception in DisplayAction(%s): %s', $bridge->getShortName(), create_sane_exception_message($e)));
return new Response('503 Service Unavailable', 503);
return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 503);
}
}
$this->logger->error(sprintf('Exception in DisplayAction(%s)', $bridge->getShortName()), ['e' => $e]);
@@ -140,7 +143,7 @@ class DisplayAction implements ActionInterface
// Render the exception as a feed item
$items[] = $this->createFeedItemFromException($e, $bridge);
} elseif ($errorOutput === 'http') {
return new Response(render(__DIR__ . '/../templates/error.html.php', ['e' => $e]), 500);
return new Response(render(__DIR__ . '/../templates/exception.html.php', ['e' => $e]), 500);
} elseif ($errorOutput === 'none') {
// Do nothing (produces an empty feed)
}
@@ -173,7 +176,7 @@ class DisplayAction implements ActionInterface
$item->setUid($bridge->getName() . '_' . $uniqueIdentifier);
$content = render_template(__DIR__ . '/../templates/bridge-error.html.php', [
'error' => render_template(__DIR__ . '/../templates/error.html.php', ['e' => $e]),
'error' => render_template(__DIR__ . '/../templates/exception.html.php', ['e' => $e]),
'searchUrl' => self::createGithubSearchUrl($bridge),
'issueUrl' => self::createGithubIssueUrl($bridge, $e, create_sane_exception_message($e)),
'maintainer' => $bridge->getMaintainer(),