[index] Use functions to build exception messages

This commit is contained in:
logmanoriginal 2017-07-29 01:07:19 +02:00
parent dea0f8b54a
commit 4fb363a3ae

View File

@ -166,38 +166,9 @@ try {
$bridge->setCache($cache); $bridge->setCache($cache);
$bridge->setDatas($params); $bridge->setDatas($params);
} catch(Exception $e){ } catch(Exception $e){
$title = $bridge->getName() . ' failed with error ' . $e->getCode();
// Build a GitHub compatible message
$body = 'Error message: `'
. $e->getmessage()
. "`\nQuery string: `"
. $_SERVER['QUERY_STRING'] . '`';
$link = buildGitHubIssueQuery($title, $body, 'bug report', $bridge->getMaintainer());
$message = <<<EOD
<!DOCTYPE html>
<html lang="en">
<head>
<title>{$e->getCode()} - {$e->getMessage()}</title>
</head>
<body>
<h1>Error {$e->getCode()} - {$e->getMessage()}</h1>
<p><strong>{$bridge->getName()}</strong> was unable to receive or process the remote website's content!
<br>Check your input parameters or press F5 to retry.
<br>If the error persists use <a href="{$link}">this</a> link to notify the bridge maintainer.
<br>Notice: After clicking on the link you can review the issue before sending it.</p>
<h2>Additional info</h2>
<p>Error code: "{$e->getCode()}"</p>
<p>Message: "{$e->getMessage()}"</p>
</body>
</html>
EOD;
header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode())); header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
header('Content-Type: text/html'); header('Content-Type: text/html');
die($message); die(buildBridgeException($e, $bridge));
} }
// Data transformation // Data transformation
@ -207,38 +178,9 @@ EOD;
$format->setExtraInfos($bridge->getExtraInfos()); $format->setExtraInfos($bridge->getExtraInfos());
$format->display(); $format->display();
} catch(Exception $e){ } catch(Exception $e){
$title = $bridge->getName() . ' failed with error ' . $e->getCode();
// Build a GitHub compatible message
$body = 'Error message: `'
. $e->getmessage()
. "`\nQuery string: `"
. $_SERVER['QUERY_STRING'] . '`';
$link = buildGitHubIssueQuery($title, $body, 'bug report', $bridge->getMaintainer());
$message = <<<EOD
<!DOCTYPE html>
<html lang="en">
<head>
<title>{$e->getCode()} - {$e->getMessage()}</title>
</head>
<body>
<h1>Error {$e->getCode()} - {$e->getMessage()}</h1>
<p>RSS-Bridge was unable to transform the contents returned by <strong>{$bridge->getName()}</strong>!
<br>Check your input parameters or press F5 to retry.
<br>If the error persists use <a href="{$link}">this</a> link to notify the bridge maintainer.
<br>Notice: After clicking on the link you can review the issue before sending it.</p>
<h2>Additional info</h2>
<p>Error code: "{$e->getCode()}"</p>
<p>Message: "{$e->getMessage()}"</p>
</body>
</html>
EOD;
header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode())); header('HTTP/1.1 ' . $e->getCode() . ' ' . Http::getMessageForCode($e->getCode()));
header('Content-Type: text/html'); header('Content-Type: text/html');
die($message); die(buildTransformException($e, $bridge));
} }
die; die;