Improved Opencast API exceptions and error handling #70
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR fixes #56,
Description
Since we are mostly using opencast api in other plugins and it belongs to this plugin, it would make sense to provide the error handling also in this plugin. Currenlty, the error handleing occurs in
block_opencast
with only 2 possible exception message; either the unexpected response or connection error. THis way, it is not possible to identify the issue just like the issue decribed in the linked issue #56.How this works
With this changes, we now provide default Guzzle Handlers to the opencast api, except for custom http error handler/middleware.
tool_opencast_http_errors
middleware a.k.a custom http error middleware is implemented to catch not only the http erros ranging from 4xx to 5xx error but also the connection error such as cURL errors mostly related to connection error such as connect timeout and unkown hostname error.moodle_exception
class but with slight touches:opencast_api_http_errors_exception
: this class is mainly designed to be used in the http error middleware. It can also be used out of the middleware, but one should pay attention to the requirements and the way to initialize this class. This works in a way, that it makes sure that the error get a local lang string from the plugin and it puts the error message, and by throwing this, the response will easily get the detailed error message as its "reason"!opencast_api_response_exception
: this class is implemented to be consumed after a request to opencast api is made as to compile and handle its response. This simply gets the response as array that hasreason
andcode
and tries to replace the reason (which already been complied and rendered by theopencast_api_http_errors_exception
) and put it as the exception message to be shown to the end-user, providing more readable and understandable messages.exception_request_404
!To Test
block_opencast
NOTE:
Following plugins also got new changes regarding this PR:
mod_opencast
=> Use new opencast api exception hanlders from API plugin moodle-mod_opencast#64block_opencast
=> Use new opencast api exceptions from API plugin moodle-block_opencast#405Moreover, it is necessary to revert back the
branch-tool-plugin
to main in these plugins, when this PR is merged!