Skip to content

Commit 9dff24a

Browse files
committed
fix return data when there is an error with more than one notification
1 parent 4231029 commit 9dff24a

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

src/WebPush.php

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function __construct(array $apiKeys = array(), $TTL = 2419200, $timeout =
7474
* @param string|null $userPublicKey
7575
* @param bool $flush If you want to flush directly (usually when you send only one notification)
7676
*
77-
* @return bool|array Return an array of information if $flush is set to true and the request has failed.
77+
* @return bool|array Return an array of information if $flush is set to true and the queued requests has failed.
7878
* Else return true.
7979
* @throws \ErrorException
8080
*/
@@ -86,7 +86,18 @@ public function sendNotification($endpoint, $payload = null, $userPublicKey = nu
8686

8787
if ($flush) {
8888
$res = $this->flush();
89-
return is_array($res) ? $res[0] : true;
89+
90+
// if there has been a problem with at least one notification
91+
if (is_array($res)) {
92+
// if there was only one notification, return the informations directly
93+
if (count($res) === 1) {
94+
return $res[0];
95+
}
96+
97+
return $res;
98+
}
99+
100+
return true;
90101
}
91102

92103
return true;

0 commit comments

Comments
 (0)