Skip to content

Commit

Permalink
Adds forbidden exception
Browse files Browse the repository at this point in the history
Refactor custom exceptions
  • Loading branch information
samgeorges committed May 23, 2022
1 parent 02464b9 commit 3a6d908
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 22 deletions.
8 changes: 8 additions & 0 deletions helpers/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?php

/**
* ForbiddenException
*
* @see October\Rain\Exception\ForbiddenException
*/
class ForbiddenException extends October\Rain\Exception\ForbiddenException {}
25 changes: 3 additions & 22 deletions src/Exception/ErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,8 @@ public function handleException(Throwable $proposedException)
ob_end_clean();
}

// Not found exceptions
if ($this->isNotFoundException($proposedException)) {
// Friendly 404 pages are used
if (($customNotFound = $this->handleCustomNotFound()) !== null) {
return $customNotFound;
}

return;
}

// Friendly error pages are used
if (($customError = $this->handleCustomError()) !== null) {
if (($customError = $this->handleCustomError($proposedException)) !== null) {
return $customError;
}

Expand Down Expand Up @@ -161,18 +151,9 @@ public function beforeHandleError($exception)
/**
* handleCustomError checks if using a custom error page, if so return the contents.
* Return NULL if a custom error is not set up.
* @return mixed Error page contents.
*/
public function handleCustomError()
{
}

/**
* handleCustomNotFound checks if using a custom 404 page, if so return the contents.
* Return NULL if a custom 404 is not set up.
* @return mixed 404 page contents.
* @return mixed
*/
public function handleCustomNotFound()
public function handleCustomError($exception)
{
}

Expand Down
12 changes: 12 additions & 0 deletions src/Exception/ForbiddenException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php namespace October\Rain\Exception;

/**
* ForbiddenException represents a permission denied exception and
* these will redirect to the nearest access denied / 403 page.
*
* @package october\exception
* @author Alexey Bobkov, Samuel Georges
*/
class ForbiddenException extends ExceptionBase
{
}
4 changes: 4 additions & 0 deletions src/Foundation/Exception/Handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Support\Responsable;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use October\Rain\Exception\ForbiddenException;
use October\Rain\Exception\NotFoundException;
use October\Rain\Exception\AjaxException;
use ReflectionFunction;
Expand Down Expand Up @@ -166,6 +167,9 @@ protected function getStatusCode($exception)
if ($exception instanceof HttpExceptionInterface) {
$code = $exception->getStatusCode();
}
elseif ($exception instanceof ForbiddenException) {
$code = 403;
}
elseif ($exception instanceof AjaxException) {
$code = 406;
}
Expand Down

0 comments on commit 3a6d908

Please sign in to comment.