Skip to content

Commit

Permalink
feat: theme error page
Browse files Browse the repository at this point in the history
Signed-off-by: Richard Steinmetz <richard@steinmetz.cloud>
  • Loading branch information
st3iny committed Jul 3, 2023
1 parent 5d9d37e commit 785342c
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions lib/private/legacy/OC_Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Thomas Müller <thomas.mueller@tmit.eu>
* @author Vincent Petry <vincent@nextcloud.com>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* @license AGPL-3.0
*
Expand All @@ -38,7 +39,9 @@
*
*/
use OC\TemplateLayout;
use OCP\AppFramework\Http\Events\BeforeTemplateRenderedEvent;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\EventDispatcher\IEventDispatcher;
use OCP\Util;

require_once __DIR__.'/template/functions.php';
Expand Down Expand Up @@ -292,10 +295,17 @@ public static function printErrorPage($error_msg, $hint = '', $statusCode = 500)

http_response_code($statusCode);
try {
$content = new \OC_Template('', 'error', 'error', false);
$errors = [['error' => $error_msg, 'hint' => $hint]];
$content->assign('errors', $errors);
$content->printPage();
$response = new TemplateResponse(
'',
'error',
['errors' => [['error' => $error_msg, 'hint' => $hint]]],
TemplateResponse::RENDER_AS_ERROR,
$statusCode,
);
$event = new BeforeTemplateRenderedEvent(false, $response);
\OC::$server->get(IEventDispatcher::class)->dispatchTyped($event);

print($response->render());
} catch (\Exception $e) {
$logger = \OC::$server->getLogger();
$logger->error("$error_msg $hint", ['app' => 'core']);
Expand Down

0 comments on commit 785342c

Please sign in to comment.