Alymosul / laravel-exponent-push-notifications

Exponent push notifications driver for laravel 5
MIT License
144 stars 77 forks source link

ErrorException: Undefined index: data #59

Open salvationarinze opened 4 years ago

salvationarinze commented 4 years ago

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

Alymosul commented 4 years ago

which version are you using?

salvationarinze commented 4 years ago

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

liharsw commented 4 years ago

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

liharsw commented 4 years ago

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

Alymosul commented 4 years ago

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

TomaszNiedzielski commented 4 years ago

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

Yeah I got the same problem

salvationarinze commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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

GossTLW commented 4 years ago

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

GossTLW commented 4 years ago

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);

}

`

ninjacoder96 commented 4 years ago

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

Trashpants commented 4 years ago

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?

pajkho commented 3 years ago

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

Alymosul commented 3 years ago

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

0plus1 commented 2 years ago

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.