Skip to content

Commit

Permalink
docs: add user guide
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Aug 4, 2022
1 parent eff6b99 commit 5358b14
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 5 deletions.
14 changes: 14 additions & 0 deletions user_guide_src/source/changelogs/v4.3.0.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

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
------

Expand Down
30 changes: 25 additions & 5 deletions user_guide_src/source/general/errors.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
---------------------
Expand All @@ -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
-----------------
Expand All @@ -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
-----------------
Expand All @@ -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.
11 changes: 11 additions & 0 deletions user_guide_src/source/installation/upgrade_430.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5358b14

Please sign in to comment.