Skip to content

Commit 37931d0

Browse files
committed
docs: add missing "HTTP Status Code and Error Views"
1 parent 0d493d1 commit 37931d0

1 file changed

Lines changed: 26 additions & 2 deletions

File tree

user_guide_src/source/general/errors.rst

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ This is used to signal a 404, Page Not Found error:
101101

102102
You can pass a message into the exception that will be displayed in place of the default message on the 404 page.
103103

104-
When thrown, the system will show the view found at
105-
**app/Views/errors/html/error_404.php**. You should customize all of the error views for your site.
104+
For the default 404 view file location, see :ref:`http-status-code-and-error-views`.
106105

107106
If, in **app/Config/Routing.php** or **app/Config/Routes.php**, you have specified
108107
a :ref:`404-override`, that will be called instead of the standard 404 page.
@@ -161,6 +160,31 @@ Since v4.3.0, you can specify the HTTP status code for your Exception class to i
161160

162161
When an exception implementing ``HTTPExceptionInterface`` is caught by CodeIgniter's exception handler, the Exception code will become the HTTP status code.
163162

163+
.. _http-status-code-and-error-views:
164+
165+
HTTP Status Code and Error Views
166+
================================
167+
168+
The exception handler displays the error view corresponding to the HTTP status
169+
code, if it exists.
170+
171+
For example, ``PageNotFoundException`` implements the ``HTTPExceptionInterface``,
172+
so its exception code ``404`` will be the HTTP status code. Therefore if it is
173+
thrown, the system will show the **error_404.php** in the **app/Views/errors/html**
174+
folder when it is a web request. If it is invoked via CLI, the system will show
175+
the **error_404.php** in the **app/Views/errors/cli** folder.
176+
177+
You should customize all of the error views in the **app/Views/error** folder for
178+
your site.
179+
180+
You can also create error views for specific HTTP status code. For example, if
181+
you want to create an error view for "400 Bad Request", add **error_400.php**.
182+
183+
.. warning:: If an error view file with the corresponding HTTP status code exists,
184+
the exception handler will display that file regardless of the environment.
185+
The view file must be implemented in such a way that it does not display
186+
detailed error messages in production environment by yourself.
187+
164188
.. _error-specify-exit-code:
165189

166190
Specify Exit Code in Your Exception

0 commit comments

Comments
 (0)