From d297e9c491223bedbddf7e2553680c6ff1c8fd5e Mon Sep 17 00:00:00 2001 From: dannylamb Date: Tue, 28 Aug 2018 17:27:11 -0300 Subject: [PATCH] Catching exceptions when generating events to get published on the queue (#93) --- src/EventGenerator/EmitEvent.php | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/EventGenerator/EmitEvent.php b/src/EventGenerator/EmitEvent.php index 32922e61..2ee5bd55 100644 --- a/src/EventGenerator/EmitEvent.php +++ b/src/EventGenerator/EmitEvent.php @@ -128,12 +128,25 @@ abstract class EmitEvent extends ConfigurableActionBase implements ContainerFact } // Generate event as stomp message. - $user = $this->entityTypeManager->getStorage('user')->load($this->account->id()); - $data = $this->generateData($entity); - $message = new Message( - $this->eventGenerator->generateEvent($entity, $user, $data), - ['Authorization' => "Bearer $token"] - ); + try { + $user = $this->entityTypeManager->getStorage('user')->load($this->account->id()); + $data = $this->generateData($entity); + $message = new Message( + $this->eventGenerator->generateEvent($entity, $user, $data), + ['Authorization' => "Bearer $token"] + ); + } + catch (\RuntimeException $e) { + // Notify the user the event couldn't be generated and abort. + \Drupal::logger('islandora')->error( + t('Error generating event: @msg', ['@msg' => $e->getMessage()]) + ); + drupal_set_message( + t('Error generating event: @msg', ['@msg' => $e->getMessage()]), + 'error' + ); + return; + } // Send the message. try {