From 1693e6ef10a7ca0439a37d26427dd9b951d89bac Mon Sep 17 00:00:00 2001 From: Christian Wolf Date: Fri, 28 Feb 2025 13:29:15 +0100 Subject: [PATCH] Moving section handling errors Signed-off-by: Christian Wolf --- developer_manual/basics/controllers.rst | 51 ++++++++++++------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/developer_manual/basics/controllers.rst b/developer_manual/basics/controllers.rst index e46bb14dd..022631d5b 100644 --- a/developer_manual/basics/controllers.rst +++ b/developer_manual/basics/controllers.rst @@ -523,6 +523,31 @@ Why does this work? Because the dispatcher sees that the controller did not retu Handling errors ^^^^^^^^^^^^^^^ +Sometimes a request should fail, for instance if an author with id 1 is requested but does not exist. In that case use an appropriate `HTTP error code `_ to signal the client that an error occurred. + +Each response subclass has access to the **setStatus** method which lets you set an HTTP status code. To return a JSONResponse signaling that the author with id 1 has not been found, use the following code: + +.. code-block:: php + + `_ to signal the client that an error occurred. - -Each response subclass has access to the **setStatus** method which lets you set an HTTP status code. To return a JSONResponse signaling that the author with id 1 has not been found, use the following code: - -.. code-block:: php - -