summaryrefslogtreecommitdiff
path: root/app/Http/Controllers/ErrorController.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Http/Controllers/ErrorController.php')
-rw-r--r--app/Http/Controllers/ErrorController.php148
1 files changed, 76 insertions, 72 deletions
diff --git a/app/Http/Controllers/ErrorController.php b/app/Http/Controllers/ErrorController.php
index e39851da46..c5e21aee5d 100644
--- a/app/Http/Controllers/ErrorController.php
+++ b/app/Http/Controllers/ErrorController.php
@@ -31,86 +31,90 @@ use Whoops\Run;
/**
* Controller for error handling.
*/
-class ErrorController extends AbstractBaseController {
- /**
- * No route was match? Send the user somewhere sensible, if we can.
- *
- * @param Request $request
- *
- * @return Response
- */
- public function noRouteFound(Request $request): Response {
- $tree = $request->attributes->get('tree');
+class ErrorController extends AbstractBaseController
+{
+ /**
+ * No route was match? Send the user somewhere sensible, if we can.
+ *
+ * @param Request $request
+ *
+ * @return Response
+ */
+ public function noRouteFound(Request $request): Response
+ {
+ $tree = $request->attributes->get('tree');
- // The tree exists, we have access to it, and it is fully imported.
- if ($tree instanceof Tree && $tree->getPreference('imported') === '1') {
- return new RedirectResponse(route('tree-page', ['ged' => $tree->getName()]));
- }
+ // The tree exists, we have access to it, and it is fully imported.
+ if ($tree instanceof Tree && $tree->getPreference('imported') === '1') {
+ return new RedirectResponse(route('tree-page', ['ged' => $tree->getName()]));
+ }
- // Not logged in?
- if (!Auth::check()) {
- return new RedirectResponse(route('login', ['url' => $request->getRequestUri()]));
- }
+ // Not logged in?
+ if (!Auth::check()) {
+ return new RedirectResponse(route('login', ['url' => $request->getRequestUri()]));
+ }
- // No tree or tree not imported?
- if (Auth::isAdmin()) {
- return new RedirectResponse(route('admin-trees'));
- }
+ // No tree or tree not imported?
+ if (Auth::isAdmin()) {
+ return new RedirectResponse(route('admin-trees'));
+ }
- return $this->viewResponse('errors/no-tree-access', [ 'title' => '' ]);
- }
+ return $this->viewResponse('errors/no-tree-access', ['title' => '']);
+ }
- /**
- * Convert an exception into an error message
- *
- * @param HttpException $ex
- *
- * @return Response
- */
- public function errorResponse(HttpException $ex): Response {
- return $this->viewResponse('alerts/danger', [
- 'title' => 'Error',
- 'alert' => $ex->getMessage(),
- ], $ex->getStatusCode());
- }
+ /**
+ * Convert an exception into an error message
+ *
+ * @param HttpException $ex
+ *
+ * @return Response
+ */
+ public function errorResponse(HttpException $ex): Response
+ {
+ return $this->viewResponse('alerts/danger', [
+ 'title' => 'Error',
+ 'alert' => $ex->getMessage(),
+ ], $ex->getStatusCode());
+ }
- /**
- * Convert an exception into an error message
- *
- * @param Request $request
- * @param Throwable $ex
- *
- * @return Response
- */
- public function unhandledExceptionResponse(Request $request, Throwable $ex): Response {
- // Create a stack dump for the exception
- $whoops = new Run;
- $whoops->allowQuit(false);
- $whoops->writeToOutput(false);
- $whoops->pushHandler(new PlainTextHandler);
- $error = $whoops->handleException($ex);
+ /**
+ * Convert an exception into an error message
+ *
+ * @param Request $request
+ * @param Throwable $ex
+ *
+ * @return Response
+ */
+ public function unhandledExceptionResponse(Request $request, Throwable $ex): Response
+ {
+ // Create a stack dump for the exception
+ $whoops = new Run;
+ $whoops->allowQuit(false);
+ $whoops->writeToOutput(false);
+ $whoops->pushHandler(new PlainTextHandler);
+ $error = $whoops->handleException($ex);
- // We do not need to show the full path.
- $error = str_replace(' ' . WT_ROOT, ' /', $error);
+ // We do not need to show the full path.
+ $error = str_replace(' ' . WT_ROOT, ' /', $error);
- try {
- Log::addErrorLog($error);
- } catch (Throwable $ex2) {
- // Must have been a problem with the database. Nothing we can do here.
- }
+ try {
+ Log::addErrorLog($error);
+ } catch (Throwable $ex2) {
+ // Must have been a problem with the database. Nothing we can do here.
+ }
- if ($request->isXmlHttpRequest()) {
- return new Response(view('alerts/danger', ['alert' => $error]), Response::HTTP_INTERNAL_SERVER_ERROR);
- }
+ if ($request->isXmlHttpRequest()) {
+ return new Response(view('alerts/danger', ['alert' => $error]), Response::HTTP_INTERNAL_SERVER_ERROR);
+ }
- try {
- return $this->viewResponse('errors/unhandled-exception', [
- 'title' => 'Error',
- 'error' => $error,
- ], Response::HTTP_INTERNAL_SERVER_ERROR);
- } catch (Throwable $ex2) {
- // An error occured in the layout? Just show the error.
- return new Response($error, Response::HTTP_INTERNAL_SERVER_ERROR);
- }
- }
+ try {
+ return $this->viewResponse('errors/unhandled-exception', [
+ 'title' => 'Error',
+ 'error' => $error,
+ ], Response::HTTP_INTERNAL_SERVER_ERROR);
+ } catch (Throwable $ex2) {
+ // An error occured in the layout? Just show the error.
+ return new Response($error, Response::HTTP_INTERNAL_SERVER_ERROR);
+ }
+ }
}