laravel-exponent-push-notifications icon indicating copy to clipboard operation
laravel-exponent-push-notifications copied to clipboard

ErrorException: Undefined index: data

Open salvationarinze opened this issue 4 years ago • 16 comments

This is issue has started again. I queued up my notification and on send, it was failing. Please take a look.

ErrorException: Undefined index: data in /vendor/alymosul/exponent-server-sdk-php/lib/Expo.php:199

salvationarinze avatar May 16 '20 10:05 salvationarinze

which version are you using?

Alymosul avatar May 19 '20 13:05 Alymosul

@Alymosul Version 2.1. It was working all well and good and suddenly began doing this

salvationarinze avatar May 19 '20 19:05 salvationarinze

in notification table duplicate entry with the same key, the problem come from that.

liharsw avatar May 27 '20 15:05 liharsw

in notification table duplicate entry with the same key, the problem come from that.

make sure don't using another expo project in same key

liharsw avatar May 27 '20 16:05 liharsw

That error could occur because of different problems. Can you debug the response you got from ExpoAPI?

Alymosul avatar May 28 '20 10:05 Alymosul

in notification table duplicate entry with the same key, the problem come from that.

Yeah I got the same problem

TomaszNiedzielski avatar May 28 '20 15:05 TomaszNiedzielski

in notification table duplicate entry with the same key, the problem come from that.

make sure don't using another expo project in same key

Yes, I deleted duplicate keys and it worked. Now, how can I stopped this from happening again please, given that the same user can login from multiple devices

salvationarinze avatar May 29 '20 16:05 salvationarinze

That error could occur because of different problems. Can you debug the response you got from ExpoAPI?

/vendor/alymosul/exponent-server-sdk-php/lib/Expo.php:199 /vendor/alymosul/exponent-server-sdk-php/lib/Expo.php:110 /vendor/alymosul/laravel-exponent-push-notifications/src/ExpoChannel.php:55 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:146 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:105 /vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php:19 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php:107 /vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php:54 /vendor/laravel/framework/src/Illuminate/Notifications/SendQueuedNotifications.php:74

salvationarinze avatar May 30 '20 23:05 salvationarinze

@Derewith I wrote an SQL to do that and I manually inserted/updated the table myself

salvationarinze avatar Jun 08 '20 23:06 salvationarinze

Hello do you have fixed this problem i have the same problem when i set a setJsonData on this function toExpoPush($notifiable) image

GossTLW avatar Jun 16 '20 23:06 GossTLW

I fixed mine. i only cast to object the array value to setJsonData

` public function toExpoPush($notifiable) { $reservations = (new Reservation())->getOneReservationByDriver($this->reservation->usager_id,$this->reservation->id);

    return ExpoMessage::create()
        ->badge(1)
        ->enableSound()
        ->title("Reservation request")
        ->setJsonData((object) $reservations->toArray())
        ->body("A costumer want your service to go to ". $this->reservation->destination);

}

`

GossTLW avatar Jun 16 '20 23:06 GossTLW

Hi. can someone help me? I cant seem to figure out why the expo is not saving the key and index in the laravel

ninjacoder96 avatar Jul 07 '20 07:07 ninjacoder96

We're also getting this issue if we attempt to add another push token to a users account. (the duplicate key issue)

Where as before we could add as many as we liked with no issue now upgrading to 2.1 we get this error as soon as a user registers a second push token.

How is anyone else handling this?

Trashpants avatar Aug 10 '20 09:08 Trashpants

@Alymosul isnt possible to catch this error and log it to the laravel error log instead of it crashing because of undefined index?

pajkho avatar Aug 22 '21 14:08 pajkho

@Trashpants are you using the database or a file as the storage driver?

Alymosul avatar Sep 09 '21 10:09 Alymosul

Hi, I am an expert on this error and it's the main reason why I moved away from this library.

As @Trashpants says it's 100% related to having multiple push tokens on a single user entity (which is quite a common case).

And the error itself is due to the library assuming there is a data key in the returned array when, in case of errors is not there.

This is the returned error from expo:

array:2 [
  "body" => "{"errors":[{"code":"PUSH_TOO_MANY_EXPERIENCE_IDS","message":"All push notification messages in the same request must be for the same project; check the details field to investigate conflicting tokens.","details":{REDACTED}, "isTransient":false}]}"
  "status_code" => 400
]

See here: https://github.com/expo/expo/issues/6771

in particular:

Notifications to different experience IDs must be sent in different requests, so you will not see any errors if you batch your push notifications by experienceId

The issue is that sometimes (when using multiple expo accounts) a token gets registered to the wrong exprience id.

0plus1 avatar Sep 20 '21 05:09 0plus1