Skip to content
Snippets Groups Projects

Issue #3472116 by viniciusrp: ErrorException(code: 0): Subscription should...

2 files
+ 29
2
Compare changes
  • Side-by-side
  • Inline
Files
2
+ 28
1
@@ -2,6 +2,7 @@
namespace Drupal\social_pwa;
use Drupal\Core\Logger\LoggerChannelFactoryInterface;
use Drupal\Core\State\StateInterface;
use Drupal\Core\Url;
use Drupal\user\UserDataInterface;
@@ -27,6 +28,13 @@ class WebPushManager implements WebPushManagerInterface {
*/
protected $userData;
/**
* A logger instance.
*
* @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
*/
protected $logger;
/**
* Create a new WebPushManager instance.
*
@@ -34,10 +42,13 @@ class WebPushManager implements WebPushManagerInterface {
* The Drupal state.
* @param \Drupal\user\UserDataInterface $userData
* Drupal user data.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* Drupal logger channel.
*/
public function __construct(StateInterface $state, UserDataInterface $userData) {
public function __construct(StateInterface $state, UserDataInterface $userData, LoggerChannelFactoryInterface $logger) {
$this->state = $state;
$this->userData = $userData;
$this->logger = $logger;
}
/**
@@ -68,6 +79,22 @@ class WebPushManager implements WebPushManagerInterface {
$user_data = [];
}
// Check if any mandatory field is empty.
$subscription_data = current($user_data);
if (
empty($subscription_data['endpoint'])
|| empty($subscription_data['key'])
|| empty($subscription_data['token'])
) {
$this->logger
->get('social_pwa')
->error('The subscription data from user id @user-id is wrong, check this user subscription to fix.', [
'@user-id' => $user->id(),
]);
return [];
}
return array_map(
static function ($subscription) {
return new Subscription(
Loading