diff --git a/lib/Exceptions.php b/lib/Exceptions.php index f3486a7b..18c09d01 100644 --- a/lib/Exceptions.php +++ b/lib/Exceptions.php @@ -102,3 +102,93 @@ function buildGitHubIssueQuery($title, $body, $labels = null, $maintainer = null return $uri; } + +/** + * Returns the exception message as HTML string + * + * @param $e Exception The exception to show + * @param $bridge object The bridge object + * @return string Returns the exception as HTML string. Returns null if the + * provided parameter are invalid + */ +function buildBridgeException($e, $bridge){ + if(!($e instanceof \Exception) || !($bridge instanceof \BridgeInterface)){ + return null; + } + + $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 = << + + + {$e->getCode()} - {$e->getMessage()} + + +

Error {$e->getCode()} - {$e->getMessage()}

+

{$bridge->getName()} was unable to receive or process the remote website's content! +
Check your input parameters or press F5 to retry. +
If the error persists use this link to notify the bridge maintainer. +
Notice: After clicking on the link you can review the issue before sending it.

+

Additional info

+

Error code: "{$e->getCode()}"

+

Message: "{$e->getMessage()}"

+ + +EOD; + + return $message; +} + +/** + * Returns the exception message as HTML string + * + * @param $e Exception The exception to show + * @param $bridge object The bridge object + * @return string Returns the exception as HTML string. Returns null if the + * provided parameter are invalid + */ +function buildTransformException($e, $bridge){ + if(!($e instanceof \Exception) || !($bridge instanceof \BridgeInterface)){ + return null; + } + + $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 = << + + + {$e->getCode()} - {$e->getMessage()} + + +

Error {$e->getCode()} - {$e->getMessage()}

+

RSS-Bridge was unable to transform the contents returned by {$bridge->getName()}! +
Check your input parameters or press F5 to retry. +
If the error persists use this link to notify the bridge maintainer. +
Notice: After clicking on the link you can review the issue before sending it.

+

Additional info

+

Error code: "{$e->getCode()}"

+

Message: "{$e->getMessage()}"

+ + +EOD; + + return $message; +}