Skip to content

Commit

Permalink
fix(dev): Adjust Exception explanations in OpenAPI tutorial
Browse files Browse the repository at this point in the history
Signed-off-by: provokateurin <kate@provokateurin.de>
  • Loading branch information
provokateurin authored and backportbot[bot] committed Jun 20, 2024
1 parent 2b1e91b commit c0a9b9c
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions developer_manual/client_apis/OCS/ocs-openapi.rst
Original file line number Diff line number Diff line change
Expand Up @@ -185,33 +185,33 @@ If you are working with an existing API where you can not break compatibility, y
return DataResponse([]);
}
DO NOT throw exceptions
^^^^^^^^^^^^^^^^^^^^^^^
DO NOT throw non-OCS*Exceptions
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Return valid responses with an error message instead.
Only use OCS*Exceptions as any other Exceptions do not produce JSON responses.

.. collapse:: Examples

.. code-block:: php
:caption: Bad
/**
* @throws OCSBadRequestException
* @throws BadRequestException
*/
public function someControllerMethod() {
...
throw new OCSBadRequestException("some message");
throw new BadRequestException([]);
}
.. code-block:: php
:caption: Good
/**
* @return DataResponse<Http::STATUS_BAD_REQUEST, array{message: string}, array{}>
* @throws OCSBadRequestException
*/
public function someControllerMethod() {
...
return DataResponse(["message" => "some message"], Http::STATUS_BAD_REQUEST);
throw new OCSBadRequestException("some message");
}
DO use the same data structures for the same group of responses
Expand Down Expand Up @@ -643,7 +643,6 @@ How to handle exceptions
------------------------

Sometimes you want to end with an exception instead of returning a response.
It is better to not do it, but when migrating existing APIs you might have to deal with exceptions.
For this example our ``update`` will throw an exception when the ETag does not match:

.. code-block:: php
Expand Down Expand Up @@ -673,8 +672,7 @@ Adding the correct annotation works like this:
}
The description after the exception class name works exactly like the description for the status codes we added earlier.
Note that the resulting response will be in plain text and no longer in JSON.
Therefore it is not recommended to use exceptions to return errors.
Note that you should only used OCS*Exceptions, as any other Exception will result in a plain text body instead of JSON.

How to ignore certain endpoints
-------------------------------
Expand Down

0 comments on commit c0a9b9c

Please sign in to comment.