Skip to content

Commit

Permalink
Handle exceptions when creating an error page
Browse files Browse the repository at this point in the history
  • Loading branch information
budziam committed Oct 4, 2021
1 parent d671b89 commit deeac56
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion includes/Http/Responses/ResponseFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Translation\TranslationManager;
use App\Translation\Translator;
use App\View\Renders\ErrorRenderer;
use Exception;
use Symfony\Component\HttpFoundation\AcceptHeader;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\RedirectResponse;
Expand Down Expand Up @@ -94,7 +95,12 @@ public function createError(Request $request, $id, $text, $status = null)
return new ApiResponse($id, $text, false, [], $status ?: 200);
}

return new HtmlResponse($this->errorRenderer->render("$status", $request), $status);
try {
$body = $this->errorRenderer->render("$status", $request);
return new HtmlResponse($body, $status);
} catch (Exception $e) {
return new HtmlResponse("$id: $text", $status);
}
}

public function createUnauthorized(Request $request)
Expand Down

0 comments on commit deeac56

Please sign in to comment.