From 4cdcd19597c9d45d5c4d08f3e06a51e9a875435c Mon Sep 17 00:00:00 2001 From: Albert221 Date: Thu, 7 Jan 2016 17:55:08 +0100 Subject: [PATCH] #719 Fixed PermissionDeniedException ...causing Whoops on debug and 500 HTTP error instead of 403 Forbidden error page. --- framework/core/error/403.html | 13 +++++++++++++ .../Core/Exception/PermissionDeniedException.php | 4 ++++ framework/core/src/Http/Middleware/HandleErrors.php | 2 +- 3 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 framework/core/error/403.html diff --git a/framework/core/error/403.html b/framework/core/error/403.html new file mode 100644 index 000000000..1ed30a168 --- /dev/null +++ b/framework/core/error/403.html @@ -0,0 +1,13 @@ + + + + + + + + +

403 Forbidden

+

You do not have permissions to access this page.

+ + + \ No newline at end of file diff --git a/framework/core/src/Core/Exception/PermissionDeniedException.php b/framework/core/src/Core/Exception/PermissionDeniedException.php index f45c4cfbd..b19268566 100644 --- a/framework/core/src/Core/Exception/PermissionDeniedException.php +++ b/framework/core/src/Core/Exception/PermissionDeniedException.php @@ -14,4 +14,8 @@ use Exception; class PermissionDeniedException extends Exception { + public function __construct($message = null, $code = 403, Exception $previous = null) + { + parent::__construct($message, $code, $previous); + } } diff --git a/framework/core/src/Http/Middleware/HandleErrors.php b/framework/core/src/Http/Middleware/HandleErrors.php index e43eb71fd..3e85b189f 100644 --- a/framework/core/src/Http/Middleware/HandleErrors.php +++ b/framework/core/src/Http/Middleware/HandleErrors.php @@ -52,7 +52,7 @@ class HandleErrors implements ErrorMiddlewareInterface $status = $errorCode; } - if ($this->debug && $errorCode !== 404) { + if ($this->debug && ! in_array($errorCode, [403, 404])) { $whoops = new WhoopsMiddleware; return $whoops($error, $request, $response, $out);