Verified Commit 30eb4c8e authored by Richard Weinhold's avatar Richard Weinhold 🔨

adds better error handling to APNS handler

parent c6d2fd4e
......@@ -153,19 +153,35 @@ class APNSHandler extends PushHandler
$encodedPayload = json_encode($payload);
// create and write notification for each single device
foreach ($devices as $device) {
try {
set_error_handler(static function (int $errno, string $errstr): bool {
if (0 === error_reporting()) {
// error was suppressed with the @-operator
return false;
}
throw new RuntimeException("Sending to APNS failed: [{$errno}] - {$errstr}");
});
// create and write notification for each single device
foreach ($devices as $device) {
// build binary notification
$notification = $this->_buildNotification($device, $encodedPayload, $arbitrary, $arbitrary['command']);
// write into stream and apply result onto previous results
if (false === fwrite($stream, $notification)) {
$result = false;
}
}
// build binary notification
$notification = $this->_buildNotification($device, $encodedPayload, $arbitrary, $arbitrary['command']);
// remove custom fwrite() error-handler
restore_error_handler();
return $result;
// write into stream and apply result onto previous results
$result = $result && (bool)@fwrite($stream, $notification);
} finally {
// remember to close the stream when finished
fclose($stream);
}
// remember to close the stream when finished
@fclose($stream);
return $result;
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment