Skip to content

Commit b2e11f2

Browse files
authored
Merge pull request #13885 from nextcloud/feat/taskprocessing-user-facing-errors
feat(dev): Add docs for UserFacingProcessingException
2 parents b180e22 + 1e9565c commit b2e11f2

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

developer_manual/digging_deeper/task_processing.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,11 @@ The task class objects have the following methods available:
242242
* ``getWebhookUri()`` This returns the webhook URI that will be notified when the task execution has ended
243243
* ``getWebhookMethod()`` This returns the HTTP method that will be used for the webhook when the task execution has ended
244244

245+
246+
.. versionadded:: 33.0.0
247+
248+
* ``getUserFacingErrorMessage()`` This returns any error message that is meant to be displayed to the user, even if a task has failed, this is not guaranteed to be set.
249+
245250
You could now schedule the task as follows:
246251

247252
.. code-block:: php
@@ -400,7 +405,10 @@ A **Task processing provider** will usually be a class that implements the inter
400405
401406
The method ``getName`` returns a string to identify the registered provider in the user interface.
402407

403-
The method ``process`` implements the task processing step. In case execution fails for some reason, you should throw a ``\OCP\TaskProcessing\Exception\ProcessingException`` with an explanatory error message. Important to note here is that ``Image``, ``Audio``, ``Video`` and ``File`` slots in the input array will be filled with ``\OCP\Files\File`` objects for your convenience. When outputting one of these you should simply return a string, the API will turn the data into a proper file for convenience. The ``$reportProgress`` parameter is a callback that you may use at will to report the task progress as a single float value between 0 and 1. Its return value will indicate if the task is still running (``true``) or if it was cancelled (``false``) and processing should be terminated.
408+
The method ``process`` implements the task processing step. In case execution fails for some reason, you should throw a ``\OCP\TaskProcessing\Exception\ProcessingException`` with an explanatory error message.
409+
Since v33.0.0 you can now also throw an ``OCP\TaskProcessing\Exception\UserFacingProcessingException`` which includes a string parameter to set for error messages that will be propagated to the end-user, make sure to always translate these into the language of the user that requested the task. The rule of thumb of when to use a user-facing error message, is as follows: When the error happened due to a mistake from the user or the user can do something to fix the error, throw a user facing error. However, do make sure to not include implementation or server details in the user facing error message, that's what the normal error message is for; it will only be visible to administrators.
410+
411+
Important to note here is that ``Image``, ``Audio``, ``Video`` and ``File`` slots in the input array will be filled with ``\OCP\Files\File`` objects for your convenience. When outputting one of these you should simply return a string, the API will turn the data into a proper file for convenience. The ``$reportProgress`` parameter is a callback that you may use at will to report the task progress as a single float value between 0 and 1. Its return value will indicate if the task is still running (``true``) or if it was cancelled (``false``) and processing should be terminated.
404412

405413
This class would typically be saved into a file in ``lib/TaskProcessing`` of your app but you are free to put it elsewhere as long as it's loadable by Nextcloud's :ref:`dependency injection container<dependency-injection>`.
406414

0 commit comments

Comments
 (0)