As continued from last commit.
use Illuminate\Http\Request;
use Illuminate\Validation\ValidationException;
use Symfony\Component\HttpKernel\Exception\HttpException;
-use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
class Handler extends ExceptionHandler
{
return $this->renderApiException($e);
}
- // Handle notify exceptions which will redirect to the
- // specified location then show a notification message.
- if ($this->isExceptionType($e, NotifyException::class)) {
- $message = $this->getOriginalMessage($e);
- if (!empty($message)) {
- session()->flash('error', $message);
- }
- return redirect($e->redirectLocation);
- }
-
return parent::render($request, $e);
}
return new JsonResponse($responseData, $code, $headers);
}
- /**
- * Check the exception chain to compare against the original exception type.
- */
- protected function isExceptionType(Exception $e, string $type): bool
- {
- do {
- if (is_a($e, $type)) {
- return true;
- }
- } while ($e = $e->getPrevious());
- return false;
- }
-
- /**
- * Get original exception message.
- */
- protected function getOriginalMessage(Exception $e): string
- {
- do {
- $message = $e->getMessage();
- } while ($e = $e->getPrevious());
- return $message;
- }
-
/**
* Convert an authentication exception into an unauthenticated response.
*
<?php namespace BookStack\Exceptions;
-class NotifyException extends \Exception
-{
+use Exception;
+use Illuminate\Contracts\Support\Responsable;
+class NotifyException extends Exception implements Responsable
+{
public $message;
public $redirectLocation;
$this->redirectLocation = $redirectLocation;
parent::__construct();
}
+
+ /**
+ * Send the response for this type of exception.
+ * @inheritdoc
+ */
+ public function toResponse($request)
+ {
+ $message = $this->getMessage();
+
+ if (!empty($message)) {
+ session()->flash('error', $message);
+ }
+
+ return redirect($this->redirectLocation);
+ }
}
use Exception;
use Illuminate\Contracts\Support\Responsable;
-use Illuminate\Http\Request;
class PrettyException extends Exception implements Responsable
{
/**
* Render a response for when this exception occurs.
- * @param Request $request
+ * @inheritdoc
*/
public function toResponse($request)
{
use BookStack\Entities\Repos\PageRepo;
use BookStack\Entities\Tools\PermissionsUpdater;
use BookStack\Exceptions\NotFoundException;
-use BookStack\Exceptions\NotifyException;
use BookStack\Exceptions\PermissionsException;
use Exception;
use Illuminate\Http\Request;
* Remove the specified page from storage.
* @throws NotFoundException
* @throws Throwable
- * @throws NotifyException
*/
public function destroy(string $bookSlug, string $pageSlug)
{
/**
* Remove the specified draft page from storage.
* @throws NotFoundException
- * @throws NotifyException
* @throws Throwable
*/
public function destroyDraft(string $bookSlug, int $pageId)