From 365168d03eeca4670b6220937e33a7fe32be232f Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sun, 9 Aug 2020 13:13:10 +0000 Subject: [PATCH] [EXCEPTION] Add ServerException and inherit previous throwable imported from v2/5ea5d3007563f76a77efbfb66936315441922542 --- src/Util/Exception/ClientException.php | 17 ++++---- src/Util/Exception/ServerException.php | 54 ++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 8 deletions(-) create mode 100644 src/Util/Exception/ServerException.php diff --git a/src/Util/Exception/ClientException.php b/src/Util/Exception/ClientException.php index 31e8dde84b..cd318f16e2 100644 --- a/src/Util/Exception/ClientException.php +++ b/src/Util/Exception/ClientException.php @@ -17,10 +17,6 @@ // along with GNU social. If not, see . // }}} -namespace App\Util\Exception; - -use Exception; - /** * Client exception. Indicates a client request contains some sort of * error. HTTP code 400 @@ -31,17 +27,22 @@ use Exception; * @author Evan Prodromou * @copyright 2009 StatusNet Inc. * @copyright 2009-2014 Free Software Foundation, Inc http://www.fsf.org + * @author Alexei Sorokin * @author Hugo Sales - * @copyright 2018-2020 Free Software Foundation, Inc http://www.fsf.org + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later */ + +namespace App\Util\Exception; + +use Exception; + class ClientException extends Exception { - public function __construct(string $message = null, int $code = 400) + public function __construct(string $message = '', int $code = 500, Throwable $previous = null) { - parent::__construct($message, $code); + parent::__construct($message, $code, $previous); } - public function __toString() { return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; diff --git a/src/Util/Exception/ServerException.php b/src/Util/Exception/ServerException.php new file mode 100644 index 0000000000..25d798c982 --- /dev/null +++ b/src/Util/Exception/ServerException.php @@ -0,0 +1,54 @@ +. + +// }}} + +/** + * Class for server exceptions + * + * Subclass of PHP Exception for server errors. + * The user typically can't fix these. + * + * @category Exception + * @package GNUsocial + * + * @author Evan Prodromou + * @copyright 2008-2010 StatusNet, Inc. + * @author Alexei Sorokin + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Util\Exception; + +use Exception; + +class ServerException extends Exception +{ + public function __construct(string $message = '', int $code = 500, Throwable $previous = null) + { + parent::__construct($message, $code, $previous); + } + + public function __toString() + { + return __CLASS__ . ": [{$this->code}]: {$this->message}\n"; + } +}