Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable28] fix(dev): Adjust Exception explanations in OpenAPI tutorial #11919

Merged
merged 1 commit into from
Sep 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading