Skip to content
Snippets Groups Projects
Commit 83f609aa authored by Patrick Kenny's avatar Patrick Kenny
Browse files

Issue #3446612 by ptmkenny: test message form should show a useful error...

Issue #3446612 by ptmkenny: test message form should show a useful error message, not throw an exception
parent a8508f7c
Branches
Tags
1 merge request!11show success and fail status messages on test form
Pipeline #170315 passed with warnings
......@@ -6,7 +6,6 @@ namespace Drupal\firebase_php\Form;
use Drupal\Core\Form\FormBase;
use Drupal\Core\Form\FormStateInterface;
use Drupal\firebase_php\Exception\FirebasePhpException;
use Drupal\firebase_php\FirebasePhpMessagingServiceInterface;
use Symfony\Component\DependencyInjection\ContainerInterface;
......@@ -87,9 +86,15 @@ final class FirebasePhpSendTestMessageForm extends FormBase {
try {
$notification = $this->messagingService->createNotification($form_state->getValue('title'), $form_state->getValue('message'));
$this->messagingService->sendMessageSingleDevice($form_state->getValue('device_token'), $notification);
$this->messenger()->addStatus($this->t('The test message has been sent to device token %token', [
'%token' => $form['device_token'],
]));
}
// @phpstan-ignore-next-line Exception is shown to admin, so no rethrowing.
catch (\Exception $e) {
throw new FirebasePhpException($e->getMessage(), 0, $e);
$this->messenger()->addError($this->t('Failed to send the test message. Error: %error', [
'%error' => $e->getMessage(),
]));
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment