Extended Error Handling
Handling exceptions during execution
To make sure the job execution engine does not retry failed messages you should use the provided functionality from the
AbstractAutomationActionHandler
to handle exceptions as a top level exception handler.
This will make sure that no unexpected exceptions are thrown without being caught and handled properly.
class VariantGeneratorHandler extends AbstractAutomationActionHandler
{
...
protected function doInvoke(JobExecutionEngineMessageInterface $message){
...
try {
...
} catch (Exception $exception) {
$this->throwUnRecoverableException($exception);
}
}
}
Abort the current action
To abort the current action you can use the abortAction
method from the AbstractAutomationActionHandler
.
You can provide additional information to the error message as well as the translation domain, thus making the error message
configurable and translatable.
With the 4th parameter of the abortAction
method you can define the exception class that should be thrown.
class VariantGeneratorHandler extends AbstractAutomationActionHandler
{
...
protected function doInvoke(JobExecutionEngineMessageInterface $message){
...
if ($validationFailed) {
$this->abortAction(
'pimcore_copilot_general_error_invalid_template',
[
'%template%' => $this->payload,
'%error%' => $e->getMessage(),
],
PimcoreCopilotBundle::TRANSLATION_DOMAIN,
RuntimeException::class
);
}
}
}
Aborting the current action will stop the execution of the current action only, that doesn't necessarily mean the whole job will be stopped. Copilot is based on the Generic Execution Engine, which has its own error handling strategy based on its configuration.
If you want to read more about the error handling strategy of the Generic Execution Engine, please refer to the Generic Execution Engine documentation.