From f313732eb5597eac6105c912af6d1894050fac32 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 4 Jul 2022 12:13:49 +0900 Subject: [PATCH 01/10] feat: add HTTPExceptionInterface and ExitExceptionInterface --- .../Database/Exceptions/DatabaseException.php | 3 ++- system/Exceptions/CastException.php | 2 +- system/Exceptions/ConfigException.php | 2 +- system/Exceptions/ExitExceptionInterface.php | 19 +++++++++++++++++++ system/Exceptions/HTTPExceptionInterface.php | 19 +++++++++++++++++++ system/Exceptions/PageNotFoundException.php | 2 +- .../Router/Exceptions/RedirectException.php | 3 ++- 7 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 system/Exceptions/ExitExceptionInterface.php create mode 100644 system/Exceptions/HTTPExceptionInterface.php diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index 13f58dc12954..92f72db4125a 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -11,9 +11,10 @@ namespace CodeIgniter\Database\Exceptions; +use CodeIgniter\Exceptions\HasExitCodeException; use Error; -class DatabaseException extends Error implements ExceptionInterface +class DatabaseException extends Error implements ExceptionInterface, HasExitCodeException { /** * Exit status code diff --git a/system/Exceptions/CastException.php b/system/Exceptions/CastException.php index 06511f73907f..9598923e7b25 100644 --- a/system/Exceptions/CastException.php +++ b/system/Exceptions/CastException.php @@ -18,7 +18,7 @@ * * @codeCoverageIgnore */ -class CastException extends CriticalError +class CastException extends CriticalError implements HasExitCodeException { use DebugTraceableTrait; diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index ced8afc6e04f..3b2867ed1c61 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -14,7 +14,7 @@ /** * Exception for automatic logging. */ -class ConfigException extends CriticalError +class ConfigException extends CriticalError implements HasExitCodeException { use DebugTraceableTrait; diff --git a/system/Exceptions/ExitExceptionInterface.php b/system/Exceptions/ExitExceptionInterface.php new file mode 100644 index 000000000000..e46d97d0fc49 --- /dev/null +++ b/system/Exceptions/ExitExceptionInterface.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Interface for Exceptions that has exception code as exit code. + */ +interface ExitExceptionInterface +{ +} diff --git a/system/Exceptions/HTTPExceptionInterface.php b/system/Exceptions/HTTPExceptionInterface.php new file mode 100644 index 000000000000..901f0b6ca33a --- /dev/null +++ b/system/Exceptions/HTTPExceptionInterface.php @@ -0,0 +1,19 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace CodeIgniter\Exceptions; + +/** + * Interface for Exceptions that has exception code as HTTP status code. + */ +interface HTTPExceptionInterface +{ +} diff --git a/system/Exceptions/PageNotFoundException.php b/system/Exceptions/PageNotFoundException.php index 7546ddaa07b7..320646966356 100644 --- a/system/Exceptions/PageNotFoundException.php +++ b/system/Exceptions/PageNotFoundException.php @@ -14,7 +14,7 @@ use Config\Services; use OutOfBoundsException; -class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface +class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface, HasHttpStatusCodeException { use DebugTraceableTrait; diff --git a/system/Router/Exceptions/RedirectException.php b/system/Router/Exceptions/RedirectException.php index d5a1616b481b..340f6fdf1873 100644 --- a/system/Router/Exceptions/RedirectException.php +++ b/system/Router/Exceptions/RedirectException.php @@ -11,12 +11,13 @@ namespace CodeIgniter\Router\Exceptions; +use CodeIgniter\Exceptions\HasHttpStatusCodeException; use Exception; /** * RedirectException */ -class RedirectException extends Exception +class RedirectException extends Exception implements HasHttpStatusCodeException { /** * HTTP status code for redirects From 85b4e6728f5aa4e8503613b3871a2aac4e1b09a6 Mon Sep 17 00:00:00 2001 From: kenjis Date: Mon, 4 Jul 2022 13:07:57 +0900 Subject: [PATCH 02/10] fix: incorrect HTTP status code or Exit code may return --- .../Database/Exceptions/DatabaseException.php | 4 ++-- system/Debug/Exceptions.php | 19 +++++++++---------- system/Entity/Exceptions/CastException.php | 14 +++++++++----- system/Exceptions/CastException.php | 2 +- system/Exceptions/ConfigException.php | 2 +- system/Exceptions/PageNotFoundException.php | 2 +- .../Router/Exceptions/RedirectException.php | 4 ++-- tests/system/Debug/ExceptionsTest.php | 15 ++++++--------- 8 files changed, 31 insertions(+), 31 deletions(-) diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index 92f72db4125a..625393e741ad 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -11,10 +11,10 @@ namespace CodeIgniter\Database\Exceptions; -use CodeIgniter\Exceptions\HasExitCodeException; +use CodeIgniter\Exceptions\ExitExceptionInterface; use Error; -class DatabaseException extends Error implements ExceptionInterface, HasExitCodeException +class DatabaseException extends Error implements ExceptionInterface, ExitExceptionInterface { /** * Exit status code diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 3ec1230291ea..74fb93679ae4 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -12,6 +12,8 @@ namespace CodeIgniter\Debug; use CodeIgniter\API\ResponseTrait; +use CodeIgniter\Exceptions\ExitExceptionInterface; +use CodeIgniter\Exceptions\HTTPExceptionInterface; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\CLIRequest; use CodeIgniter\HTTP\Exceptions\HTTPException; @@ -312,18 +314,15 @@ protected function maskSensitiveData(&$trace, array $keysToMask, string $path = */ protected function determineCodes(Throwable $exception): array { - $statusCode = abs($exception->getCode()); + $statusCode = 500; + $exitStatus = EXIT_ERROR; - if ($statusCode < 100 || $statusCode > 599) { - $exitStatus = $statusCode + EXIT__AUTO_MIN; - - if ($exitStatus > EXIT__AUTO_MAX) { - $exitStatus = EXIT_ERROR; - } + if ($exception instanceof HTTPExceptionInterface) { + $statusCode = $exception->getCode(); + } - $statusCode = 500; - } else { - $exitStatus = EXIT_ERROR; + if ($exception instanceof ExitExceptionInterface) { + $exitStatus = $exception->getCode(); } return [$statusCode, $exitStatus]; diff --git a/system/Entity/Exceptions/CastException.php b/system/Entity/Exceptions/CastException.php index 224bbdc7eb68..87d5b173309e 100644 --- a/system/Entity/Exceptions/CastException.php +++ b/system/Entity/Exceptions/CastException.php @@ -11,17 +11,21 @@ namespace CodeIgniter\Entity\Exceptions; +use CodeIgniter\Exceptions\ExitExceptionInterface; use CodeIgniter\Exceptions\FrameworkException; /** * CastException is thrown for invalid cast initialization and management. - * - * @TODO CodeIgniter\Exceptions\CastException is deprecated and this class is used. - * CodeIgniter\Exceptions\CastException has the property $code = EXIT_CONFIG, - * but this class does not have the code. */ -class CastException extends FrameworkException +class CastException extends FrameworkException implements ExitExceptionInterface { + /** + * Exit status code + * + * @var int + */ + protected $code = EXIT_CONFIG; + /** * Thrown when the cast class does not extends BaseCast. * diff --git a/system/Exceptions/CastException.php b/system/Exceptions/CastException.php index 9598923e7b25..f009a00173c1 100644 --- a/system/Exceptions/CastException.php +++ b/system/Exceptions/CastException.php @@ -18,7 +18,7 @@ * * @codeCoverageIgnore */ -class CastException extends CriticalError implements HasExitCodeException +class CastException extends CriticalError implements ExitExceptionInterface { use DebugTraceableTrait; diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index 3b2867ed1c61..1e86e41bd238 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -14,7 +14,7 @@ /** * Exception for automatic logging. */ -class ConfigException extends CriticalError implements HasExitCodeException +class ConfigException extends CriticalError implements ExitExceptionInterface { use DebugTraceableTrait; diff --git a/system/Exceptions/PageNotFoundException.php b/system/Exceptions/PageNotFoundException.php index 320646966356..e41ae6ac868d 100644 --- a/system/Exceptions/PageNotFoundException.php +++ b/system/Exceptions/PageNotFoundException.php @@ -14,7 +14,7 @@ use Config\Services; use OutOfBoundsException; -class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface, HasHttpStatusCodeException +class PageNotFoundException extends OutOfBoundsException implements ExceptionInterface, HTTPExceptionInterface { use DebugTraceableTrait; diff --git a/system/Router/Exceptions/RedirectException.php b/system/Router/Exceptions/RedirectException.php index 340f6fdf1873..a23d651855de 100644 --- a/system/Router/Exceptions/RedirectException.php +++ b/system/Router/Exceptions/RedirectException.php @@ -11,13 +11,13 @@ namespace CodeIgniter\Router\Exceptions; -use CodeIgniter\Exceptions\HasHttpStatusCodeException; +use CodeIgniter\Exceptions\HTTPExceptionInterface; use Exception; /** * RedirectException */ -class RedirectException extends Exception implements HasHttpStatusCodeException +class RedirectException extends Exception implements HTTPExceptionInterface { /** * HTTP status code for redirects diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index 3ef643c831e3..e98ba5e0b0aa 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -60,16 +60,13 @@ public function testDetermineCodes(): void { $determineCodes = $this->getPrivateMethodInvoker($this->exception, 'determineCodes'); - $this->assertSame([500, EXIT__AUTO_MIN], $determineCodes(new RuntimeException('This.'))); + $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('This.'))); $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('That.', 600))); - $this->assertSame([404, EXIT_ERROR], $determineCodes(new RuntimeException('There.', 404))); - $this->assertSame([167, EXIT_ERROR], $determineCodes(new RuntimeException('This.', 167))); - // @TODO This exit code should be EXIT_CONFIG. - $this->assertSame([500, 12], $determineCodes(new ConfigException('This.'))); - // @TODO This exit code should be EXIT_CONFIG. - $this->assertSame([500, 9], $determineCodes(new CastException('This.'))); - // @TODO This exit code should be EXIT_DATABASE. - $this->assertSame([500, 17], $determineCodes(new DatabaseException('This.'))); + $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('There.', 404))); + $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('This.', 167))); + $this->assertSame([500, EXIT_CONFIG], $determineCodes(new ConfigException('This.'))); + $this->assertSame([500, EXIT_CONFIG], $determineCodes(new CastException('This.'))); + $this->assertSame([500, EXIT_DATABASE], $determineCodes(new DatabaseException('This.'))); } public function testRenderBacktrace(): void From eff6b9956bef3239039047a8b7f1d190c852cf00 Mon Sep 17 00:00:00 2001 From: kenjis Date: Sun, 24 Jul 2022 09:58:00 +0900 Subject: [PATCH 03/10] feat: rename ExitExceptionInterface and add getExitCode() --- system/Database/Exceptions/DatabaseException.php | 14 ++++++-------- system/Debug/Exceptions.php | 6 +++--- system/Entity/Exceptions/CastException.php | 14 ++++++-------- system/Exceptions/CastException.php | 12 +++++------- system/Exceptions/ConfigException.php | 12 +++++------- ...ptionInterface.php => HasExitCodeInterface.php} | 6 +++++- 6 files changed, 30 insertions(+), 34 deletions(-) rename system/Exceptions/{ExitExceptionInterface.php => HasExitCodeInterface.php} (75%) diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index 625393e741ad..4a5878782c4c 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -11,15 +11,13 @@ namespace CodeIgniter\Database\Exceptions; -use CodeIgniter\Exceptions\ExitExceptionInterface; +use CodeIgniter\Exceptions\HasExitCodeInterface; use Error; -class DatabaseException extends Error implements ExceptionInterface, ExitExceptionInterface +class DatabaseException extends Error implements ExceptionInterface, HasExitCodeInterface { - /** - * Exit status code - * - * @var int - */ - protected $code = EXIT_DATABASE; + public function getExitCode(): int + { + return EXIT_DATABASE; + } } diff --git a/system/Debug/Exceptions.php b/system/Debug/Exceptions.php index 74fb93679ae4..af34db8188a1 100644 --- a/system/Debug/Exceptions.php +++ b/system/Debug/Exceptions.php @@ -12,7 +12,7 @@ namespace CodeIgniter\Debug; use CodeIgniter\API\ResponseTrait; -use CodeIgniter\Exceptions\ExitExceptionInterface; +use CodeIgniter\Exceptions\HasExitCodeInterface; use CodeIgniter\Exceptions\HTTPExceptionInterface; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\HTTP\CLIRequest; @@ -321,8 +321,8 @@ protected function determineCodes(Throwable $exception): array $statusCode = $exception->getCode(); } - if ($exception instanceof ExitExceptionInterface) { - $exitStatus = $exception->getCode(); + if ($exception instanceof HasExitCodeInterface) { + $exitStatus = $exception->getExitCode(); } return [$statusCode, $exitStatus]; diff --git a/system/Entity/Exceptions/CastException.php b/system/Entity/Exceptions/CastException.php index 87d5b173309e..e259447b3f76 100644 --- a/system/Entity/Exceptions/CastException.php +++ b/system/Entity/Exceptions/CastException.php @@ -11,20 +11,18 @@ namespace CodeIgniter\Entity\Exceptions; -use CodeIgniter\Exceptions\ExitExceptionInterface; use CodeIgniter\Exceptions\FrameworkException; +use CodeIgniter\Exceptions\HasExitCodeInterface; /** * CastException is thrown for invalid cast initialization and management. */ -class CastException extends FrameworkException implements ExitExceptionInterface +class CastException extends FrameworkException implements HasExitCodeInterface { - /** - * Exit status code - * - * @var int - */ - protected $code = EXIT_CONFIG; + public function getExitCode(): int + { + return EXIT_CONFIG; + } /** * Thrown when the cast class does not extends BaseCast. diff --git a/system/Exceptions/CastException.php b/system/Exceptions/CastException.php index f009a00173c1..e1f4e1231eef 100644 --- a/system/Exceptions/CastException.php +++ b/system/Exceptions/CastException.php @@ -18,16 +18,14 @@ * * @codeCoverageIgnore */ -class CastException extends CriticalError implements ExitExceptionInterface +class CastException extends CriticalError implements HasExitCodeInterface { use DebugTraceableTrait; - /** - * Exit status code - * - * @var int - */ - protected $code = EXIT_CONFIG; + public function getExitCode(): int + { + return EXIT_CONFIG; + } public static function forInvalidJsonFormatException(int $error) { diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index 1e86e41bd238..0a0a6656362e 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -14,16 +14,14 @@ /** * Exception for automatic logging. */ -class ConfigException extends CriticalError implements ExitExceptionInterface +class ConfigException extends CriticalError implements HasExitCodeInterface { use DebugTraceableTrait; - /** - * Exit status code - * - * @var int - */ - protected $code = EXIT_CONFIG; + public function getExitCode(): int + { + return EXIT_CONFIG; + } public static function forDisabledMigrations() { diff --git a/system/Exceptions/ExitExceptionInterface.php b/system/Exceptions/HasExitCodeInterface.php similarity index 75% rename from system/Exceptions/ExitExceptionInterface.php rename to system/Exceptions/HasExitCodeInterface.php index e46d97d0fc49..3380d00b816d 100644 --- a/system/Exceptions/ExitExceptionInterface.php +++ b/system/Exceptions/HasExitCodeInterface.php @@ -14,6 +14,10 @@ /** * Interface for Exceptions that has exception code as exit code. */ -interface ExitExceptionInterface +interface HasExitCodeInterface { + /** + * Returns exit status code. + */ + public function getExitCode(): int; } From cb1b570ee258167ce4377d2eed379450b09bea6e Mon Sep 17 00:00:00 2001 From: kenjis Date: Thu, 4 Aug 2022 10:23:04 +0900 Subject: [PATCH 04/10] docs: add user guide --- user_guide_src/source/changelogs/v4.3.0.rst | 14 +++++++++ user_guide_src/source/general/errors.rst | 30 +++++++++++++++---- .../source/installation/upgrade_430.rst | 11 +++++++ 3 files changed, 50 insertions(+), 5 deletions(-) diff --git a/user_guide_src/source/changelogs/v4.3.0.rst b/user_guide_src/source/changelogs/v4.3.0.rst index 3a429f6bc36b..f46df1b874fe 100644 --- a/user_guide_src/source/changelogs/v4.3.0.rst +++ b/user_guide_src/source/changelogs/v4.3.0.rst @@ -23,6 +23,20 @@ Exceptions when Database Errors Occur - The exceptions thrown by the database connection classes have been changed to ``CodeIgniter\Database\Exceptions\DatabaseException``. Previously, different database drivers threw different exception classes, but these have been unified into ``DatabaseException``. - The exceptions thrown by the ``execute()`` method of Prepared Queries have been changed to ``DatabaseException``. Previously, different database drivers might throw different exception classes or did not throw exceptions, but these have been unified into ``DatabaseException``. +HTTP Status Code and Exit Code when Exception Occurs +---------------------------------------------------- + +Previously, the CodeIgniter's Exception Handler used the *Exception code* as *HTTP status code* in some cases, and set calculated *Exit code* based on the Exception code. However there is essentially nothing to do with Exception code and HTTP Status Code or Exit code. + +- Now the Exception Handler sets HTTP status code to ``500`` and set Exit code to the constant ``EXIT_ERROR`` (= ``1``) by default. +- You can change HTTP status code or Exit code to implements ``HTTPExceptionInterface`` or ``HasExitCodeInterface`` in your Exception class. See :ref:`error-specify-http-status-code` and :ref:`error-specify-exit-code`. + +For example, the Exit code has been changed like the following: + +- If an uncaught ``ConfigException`` occurs, the Exit code is ``EXIT_CONFIG`` (= ``3``) instead of ``12``. +- If an uncaught ``CastException`` occurs, the Exit code is ``EXIT_CONFIG`` (= ``3``) instead of ``9``. +- If an uncaught ``DatabaseException`` occurs, the Exit code is ``EXIT_DATABASE`` (= ``8``) instead of ``17``. + Others ------ diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 1709969c00b5..45ba60b7635a 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -64,10 +64,10 @@ To ignore logging on other status codes, you can set the status code to ignore i .. note:: It is possible that logging still will not happen for exceptions if your current Log settings are not set up to log **critical** errors, which all exceptions are logged as. -Custom Exceptions -================= +Framework Exceptions +==================== -The following custom exceptions are available: +The following framework exceptions are available: PageNotFoundException --------------------- @@ -89,7 +89,7 @@ is not the right type, etc: .. literalinclude:: errors/008.php -This provides an HTTP status code of 500 and an exit code of 3. +This provides an exit code of 3. DatabaseException ----------------- @@ -99,7 +99,7 @@ or when it is temporarily lost: .. literalinclude:: errors/009.php -This provides an HTTP status code of 500 and an exit code of 8. +This provides an exit code of 8. RedirectException ----------------- @@ -113,3 +113,23 @@ forcing a redirect to a specific route or URL: redirect code to use instead of the default (``302``, "temporary redirect"): .. literalinclude:: errors/011.php + +.. _error-specify-http-status-code: + +Specify HTTP Status Code in Your Exception +========================================== + +Since v4.3.0, you can specify the HTTP status code for your Exception class to implement +``HTTPExceptionInterface``. + +When an exception implemented ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will be the HTTP status code. + +.. _error-specify-exit-code: + +Specify Exit Code in Your Exception +=================================== + +Since v4.3.0, you can specify the exit code for your Exception class to implement +``HasExitCodeInterface``. + +When an exception implemented ``HasExitCodeInterface`` is caught by CodeIgniter's exception handler, the code returned from the ``getExitCode()`` method will be the exit code. diff --git a/user_guide_src/source/installation/upgrade_430.rst b/user_guide_src/source/installation/upgrade_430.rst index 88e6afac64de..07e414655611 100644 --- a/user_guide_src/source/installation/upgrade_430.rst +++ b/user_guide_src/source/installation/upgrade_430.rst @@ -44,6 +44,17 @@ Add **types** to the properties in these Config classes. You may need to fix the Breaking Changes **************** +HTTP Status Code and Exit Code of Uncaught Exceptions +===================================================== + +- If you expect *Exception code* as *HTTP status code*, the HTTP status code will be changed. + In that case, you need to implements ``HTTPExceptionInterface`` in the Exception. See :ref:`error-specify-http-status-code`. +- If you expect *Exit code* based on *Exception code*, the Exit code will be changed. + In that case, you need to implements ``HasExitCodeInterface`` in the Exception. See :ref:`error-specify-exit-code`. + +Others +====== + - The exception classes may be changed when database errors occur. If you catch the exceptions, you must confirm that your code can catch the exceptions. See :ref:`exceptions-when-database-errors-occur` for details. Breaking Enhancements From 0eab5af4ceb8505472700a576b60b828e60e2082 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:25:12 +0900 Subject: [PATCH 05/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/changelogs/v4.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.3.0.rst b/user_guide_src/source/changelogs/v4.3.0.rst index f46df1b874fe..1ff079056002 100644 --- a/user_guide_src/source/changelogs/v4.3.0.rst +++ b/user_guide_src/source/changelogs/v4.3.0.rst @@ -26,7 +26,7 @@ Exceptions when Database Errors Occur HTTP Status Code and Exit Code when Exception Occurs ---------------------------------------------------- -Previously, the CodeIgniter's Exception Handler used the *Exception code* as *HTTP status code* in some cases, and set calculated *Exit code* based on the Exception code. However there is essentially nothing to do with Exception code and HTTP Status Code or Exit code. +Previously, CodeIgniter's Exception Handler used the *Exception code* as the *HTTP status code* in some cases, and calculated the *Exit code* based on the Exception code. However there should be no logical connection with Exception code and HTTP Status Code or Exit code. - Now the Exception Handler sets HTTP status code to ``500`` and set Exit code to the constant ``EXIT_ERROR`` (= ``1``) by default. - You can change HTTP status code or Exit code to implements ``HTTPExceptionInterface`` or ``HasExitCodeInterface`` in your Exception class. See :ref:`error-specify-http-status-code` and :ref:`error-specify-exit-code`. From 815cfd86e0f177fd6d7e5f8786fc22fff1e7a195 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:25:27 +0900 Subject: [PATCH 06/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/changelogs/v4.3.0.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/changelogs/v4.3.0.rst b/user_guide_src/source/changelogs/v4.3.0.rst index 1ff079056002..6f925d087e08 100644 --- a/user_guide_src/source/changelogs/v4.3.0.rst +++ b/user_guide_src/source/changelogs/v4.3.0.rst @@ -29,7 +29,7 @@ HTTP Status Code and Exit Code when Exception Occurs Previously, CodeIgniter's Exception Handler used the *Exception code* as the *HTTP status code* in some cases, and calculated the *Exit code* based on the Exception code. However there should be no logical connection with Exception code and HTTP Status Code or Exit code. - Now the Exception Handler sets HTTP status code to ``500`` and set Exit code to the constant ``EXIT_ERROR`` (= ``1``) by default. -- You can change HTTP status code or Exit code to implements ``HTTPExceptionInterface`` or ``HasExitCodeInterface`` in your Exception class. See :ref:`error-specify-http-status-code` and :ref:`error-specify-exit-code`. +- You can change HTTP status code or Exit code to implement ``HTTPExceptionInterface`` or ``HasExitCodeInterface`` in your Exception class. See :ref:`error-specify-http-status-code` and :ref:`error-specify-exit-code`. For example, the Exit code has been changed like the following: From c09628c214d1da2838ca1fc1485840b6aa355584 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:25:57 +0900 Subject: [PATCH 07/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/general/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 45ba60b7635a..2909e4152a7c 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -122,7 +122,7 @@ Specify HTTP Status Code in Your Exception Since v4.3.0, you can specify the HTTP status code for your Exception class to implement ``HTTPExceptionInterface``. -When an exception implemented ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will be the HTTP status code. +When an exception implementing ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will become the HTTP status code. .. _error-specify-exit-code: From a2df8dad68de55a542f339a30b43eee9e0cd3210 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:26:19 +0900 Subject: [PATCH 08/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/general/errors.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/general/errors.rst b/user_guide_src/source/general/errors.rst index 2909e4152a7c..fb34f2b744ad 100644 --- a/user_guide_src/source/general/errors.rst +++ b/user_guide_src/source/general/errors.rst @@ -132,4 +132,4 @@ Specify Exit Code in Your Exception Since v4.3.0, you can specify the exit code for your Exception class to implement ``HasExitCodeInterface``. -When an exception implemented ``HasExitCodeInterface`` is caught by CodeIgniter's exception handler, the code returned from the ``getExitCode()`` method will be the exit code. +When an exception implementing ``HasExitCodeInterface`` is caught by CodeIgniter's exception handler, the code returned from the ``getExitCode()`` method will become the exit code. From d4bc0faae0eb1b67b9695d8a4710fb3ed6eb7849 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:26:31 +0900 Subject: [PATCH 09/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/installation/upgrade_430.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/installation/upgrade_430.rst b/user_guide_src/source/installation/upgrade_430.rst index 07e414655611..df48cff4e547 100644 --- a/user_guide_src/source/installation/upgrade_430.rst +++ b/user_guide_src/source/installation/upgrade_430.rst @@ -48,7 +48,7 @@ HTTP Status Code and Exit Code of Uncaught Exceptions ===================================================== - If you expect *Exception code* as *HTTP status code*, the HTTP status code will be changed. - In that case, you need to implements ``HTTPExceptionInterface`` in the Exception. See :ref:`error-specify-http-status-code`. + In that case, you need to implement ``HTTPExceptionInterface`` in the Exception. See :ref:`error-specify-http-status-code`. - If you expect *Exit code* based on *Exception code*, the Exit code will be changed. In that case, you need to implements ``HasExitCodeInterface`` in the Exception. See :ref:`error-specify-exit-code`. From 9a2a0ce13d5b465d7400244e348bcf80c01f0d29 Mon Sep 17 00:00:00 2001 From: kenjis Date: Fri, 5 Aug 2022 16:26:40 +0900 Subject: [PATCH 10/10] docs: fix by proofreading Co-authored-by: MGatner --- user_guide_src/source/installation/upgrade_430.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/user_guide_src/source/installation/upgrade_430.rst b/user_guide_src/source/installation/upgrade_430.rst index df48cff4e547..060f24259572 100644 --- a/user_guide_src/source/installation/upgrade_430.rst +++ b/user_guide_src/source/installation/upgrade_430.rst @@ -50,7 +50,7 @@ HTTP Status Code and Exit Code of Uncaught Exceptions - If you expect *Exception code* as *HTTP status code*, the HTTP status code will be changed. In that case, you need to implement ``HTTPExceptionInterface`` in the Exception. See :ref:`error-specify-http-status-code`. - If you expect *Exit code* based on *Exception code*, the Exit code will be changed. - In that case, you need to implements ``HasExitCodeInterface`` in the Exception. See :ref:`error-specify-exit-code`. + In that case, you need to implement ``HasExitCodeInterface`` in the Exception. See :ref:`error-specify-exit-code`. Others ======