Error : "Cannot convert a non-failed response to an exception"
X10ASqL opened this issue · comments
Describe the bug
Error : "Cannot convert a non-failed response to an exception"
Got this error when using code $firebase->createMessaging()->validateRegistrationTokens(Token);
and the same error for this code $firebase->createMessaging()->send(message);
Code is executed inside a laravel job
Only difference that i did was upgrading my PHP version from 7.2.27 to 7.4.33 and upgrading kreait firebase-php package from 5.20 to 5.26.
Installed packages
"ext-ctype": "*",
"ext-json": "*",
"ext-mbstring": "*",
"ext-openssl": "*",
"google/auth": "1.26",
"google/cloud-core": "1.52.10",
"google/cloud-storage": "1.30.3",
"guzzlehttp/guzzle": "6.5.8",
"guzzlehttp/promises": "1.5.3",
"guzzlehttp/psr7": "1.9.1",
"kreait/clock": "1.2",
"kreait/firebase-tokens": "1.16.3",
"mtdowling/jmespath.php": "2.7.0",
"php": "7.4",
"psr/cache": "1.0.1",
"psr/log": "1.1.4",
"psr/simple-cache": "1.0.1",
"riverline/multipart-parser": "^2.1.1",
"symfony/polyfill-php80": "1.28",
"symfony/polyfill-php81": "1.28"
PHP version and extensions
composer 2.5.4 Composer package
composer-plugin-api 2.3.0 The Composer Plugin API
composer-runtime-api 2.2.2 The Composer Runtime API
ext-bcmath 7.4.33 The bcmath PHP extension
ext-bz2 7.4.33 The bz2 PHP extension
ext-calendar 7.4.33 The calendar PHP extension
ext-ctype 7.4.33 The ctype PHP extension
ext-curl 7.4.33 The curl PHP extension
ext-date 7.4.33 The date PHP extension
ext-dom 20031129 The dom PHP extension
ext-exif 7.4.33 The exif PHP extension
ext-fileinfo 7.4.33 The fileinfo PHP extension
ext-filter 7.4.33 The filter PHP extension
ext-ftp 7.4.33 The ftp PHP extension
ext-gd 7.4.33 The gd PHP extension
ext-gettext 7.4.33 The gettext PHP extension
ext-gmp 7.4.33 The gmp PHP extension
ext-hash 7.4.33 The hash PHP extension
ext-iconv 7.4.33 The iconv PHP extension
ext-json 7.4.33 The json PHP extension
ext-libxml 7.4.33 The libxml PHP extension
ext-mbstring 7.4.33 The mbstring PHP extension
ext-mysqli 7.4.33 The mysqli PHP extension
ext-mysqlnd 0 The mysqlnd PHP extension (actual version: mysqlnd 7.4.33)
ext-oci8 2.2.0 The oci8 PHP extension
ext-odbc 7.4.33 The odbc PHP extension
ext-openssl 7.4.33 The openssl PHP extension
ext-pcre 7.4.33 The pcre PHP extension
ext-pdo 7.4.33 The PDO PHP extension
ext-pdo_oci 7.4.33 The PDO_OCI PHP extension
ext-pdo_odbc 7.4.33 The PDO_ODBC PHP extension
ext-phar 7.4.33 The Phar PHP extension
ext-readline 7.4.33 The readline PHP extension
ext-reflection 7.4.33 The Reflection PHP extension
ext-session 7.4.33 The session PHP extension
ext-simplexml 7.4.33 The SimpleXML PHP extension
ext-spl 7.4.33 The SPL PHP extension
ext-tokenizer 7.4.33 The tokenizer PHP extension
ext-xml 7.4.33 The xml PHP extension
ext-xmlreader 7.4.33 The xmlreader PHP extension
ext-xmlwriter 7.4.33 The xmlwriter PHP extension
ext-zip 1.15.6 The zip PHP extension
ext-zlib 7.4.33 The zlib PHP extension
lib-bz2 1.0.8 The bz2 library
lib-curl 7.70.0 The curl library
lib-curl-libssh2 1.9.0 curl libssh2 version
lib-curl-openssl 1.1.1.19 curl OpenSSL version (1.1.1.19)
lib-curl-zlib 1.2.12 curl zlib version
lib-date-timelib 2018.04 date timelib version
lib-date-zoneinfo 2022.1 zoneinfo ("Olson") database for date
lib-fileinfo-libmagic 537 fileinfo libmagic version
lib-gd 2.0.35 The gd library
lib-gd-freetype 2.9.1 freetype version for gd
lib-gd-libjpeg 9.0 libjpeg version for gd
lib-gd-libpng 1.6.34 libpng version for gd
lib-gd-libxpm 3.5.12 libxpm version for gd
lib-gmp 6.0.0 The gmp library
lib-iconv 1.16 The iconv library
lib-libxml 2.9.10 libxml library version
lib-mbstring-libmbfl 1.3.2 mbstring libmbfl version
lib-mbstring-oniguruma 6.9.5 mbstring oniguruma version
lib-openssl 1.1.1.19 OpenSSL 1.1.1s 1 Nov 2022
lib-pcre 10.35 The pcre library
lib-pcre-unicode 13.0.0 PCRE Unicode version support
lib-zip-libzip 1.7.1 The zip-libzip library
lib-zlib 1.2.12 The zlib library
php 7.4.33 The PHP interpreter
php-ipv6 7.4.33 The PHP interpreter, with IPv6 support
php-zts 7.4.33 The PHP interpreter, with Zend Thread Safety
Steps to reproduce the issue.
public function handle()
{
$firebase = app('firebase');
$messaging = $firebase->createMessaging();
$deviceToken = User::where('id', $this->currentNotification->to_)->value('token');
if ($deviceToken <> null){
$validate = $messaging->validateRegistrationTokens($deviceToken);
if (is_null($validate['valid']) || $validate['valid'] == '') {
return;
}
$body = $this->buildBodyMessage();
$message = CloudMessage::fromArray([
'token' => $deviceToken,
'data' => ['title' => $this->title, 'message'=> $body],
]);
$messaging->send($message);
return;
}
return;
}
Error message/Stack trace
[2023-12-13 14:20:08] local.ERROR: Cannot convert a non-failed response to an exception
[2023-12-13 14:20:08] local.ERROR: Cannot convert a non-failed response to an exception {"exception":"[object] (Kreait\\Firebase\\Exception\\InvalidArgumentException(code: 0): Cannot convert a non-failed response to an exception at D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Exception\\MessagingApiExceptionConverter.php:64)
[stacktrace]
#0 D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Exception\\MessagingApiExceptionConverter.php(120): Kreait\\Firebase\\Exception\\MessagingApiExceptionConverter->convertResponse(Object(GuzzleHttp\\Psr7\\Response), Object(GuzzleHttp\\Exception\\RequestException))
#1 D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Exception\\MessagingApiExceptionConverter.php(49): Kreait\\Firebase\\Exception\\MessagingApiExceptionConverter->convertGuzzleRequestException(Object(GuzzleHttp\\Exception\\RequestException))
#2 D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Messaging\\ApiClient.php(44): Kreait\\Firebase\\Exception\\MessagingApiExceptionConverter->convertException(Object(GuzzleHttp\\Exception\\RequestException))
#3 D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Messaging.php(74): Kreait\\Firebase\\Messaging\\ApiClient->send(Object(Kreait\\Firebase\\Messaging\\Http\\Request\\SendMessageToTokens))
#4 D:\\Xampp\\htdocs\\projectName\\vendor\\kreait\\firebase-php\\src\\Firebase\\Messaging.php(103): Kreait\\Firebase\\Messaging->sendMulticast(Object(Kreait\\Firebase\\Messaging\\CloudMessage), Object(Kreait\\Firebase\\Messaging\\RegistrationTokens), true)
#5 D:\\Xampp\\htdocs\\projectName\\app\\Jobs\\SendFirebaseNotification.php(52): Kreait\\Firebase\\Messaging->validateRegistrationTokens(Object(Kreait\\Firebase\\Messaging\\RegistrationTokens))
#6 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): App\\Jobs\\SendFirebaseNotification->handle()
#7 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#8 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#9 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#10 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#11 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Bus\\Dispatcher.php(94): Illuminate\\Container\\Container->call(Array)
#12 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Bus\\Dispatcher->Illuminate\\Bus\\{closure}(Object(App\\Jobs\\SendFirebaseNotification))
#13 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(App\\Jobs\\SendFirebaseNotification))
#14 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Bus\\Dispatcher.php(98): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#15 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(83): Illuminate\\Bus\\Dispatcher->dispatchNow(Object(App\\Jobs\\SendFirebaseNotification), false)
#16 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(130): Illuminate\\Queue\\CallQueuedHandler->Illuminate\\Queue\\{closure}(Object(App\\Jobs\\SendFirebaseNotification))
#17 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Pipeline\\Pipeline.php(105): Illuminate\\Pipeline\\Pipeline->Illuminate\\Pipeline\\{closure}(Object(App\\Jobs\\SendFirebaseNotification))
#18 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(85): Illuminate\\Pipeline\\Pipeline->then(Object(Closure))
#19 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\CallQueuedHandler.php(59): Illuminate\\Queue\\CallQueuedHandler->dispatchThroughMiddleware(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(App\\Jobs\\SendFirebaseNotification))
#20 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Jobs\\Job.php(88): Illuminate\\Queue\\CallQueuedHandler->call(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Array)
#21 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(368): Illuminate\\Queue\\Jobs\\Job->fire()
#22 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(314): Illuminate\\Queue\\Worker->process('database', Object(Illuminate\\Queue\\Jobs\\DatabaseJob), Object(Illuminate\\Queue\\WorkerOptions))
#23 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Worker.php(134): Illuminate\\Queue\\Worker->runJob(Object(Illuminate\\Queue\\Jobs\\DatabaseJob), 'database', Object(Illuminate\\Queue\\WorkerOptions))
#24 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(112): Illuminate\\Queue\\Worker->daemon('database', 'Firebase', Object(Illuminate\\Queue\\WorkerOptions))
#25 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Queue\\Console\\WorkCommand.php(96): Illuminate\\Queue\\Console\\WorkCommand->runWorker('database', 'Firebase')
#26 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(36): Illuminate\\Queue\\Console\\WorkCommand->handle()
#27 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Util.php(37): Illuminate\\Container\\BoundMethod::Illuminate\\Container\\{closure}()
#28 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(93): Illuminate\\Container\\Util::unwrapIfClosure(Object(Closure))
#29 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\BoundMethod.php(37): Illuminate\\Container\\BoundMethod::callBoundMethod(Object(Illuminate\\Foundation\\Application), Array, Object(Closure))
#30 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Container\\Container.php(590): Illuminate\\Container\\BoundMethod::call(Object(Illuminate\\Foundation\\Application), Array, Array, NULL)
#31 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(134): Illuminate\\Container\\Container->call(Array)
#32 D:\\Xampp\\htdocs\\projectName\\vendor\\symfony\\console\\Command\\Command.php(255): Illuminate\\Console\\Command->execute(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#33 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Command.php(121): Symfony\\Component\\Console\\Command\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Illuminate\\Console\\OutputStyle))
#34 D:\\Xampp\\htdocs\\projectName\\vendor\\symfony\\console\\Application.php(1021): Illuminate\\Console\\Command->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#35 D:\\Xampp\\htdocs\\projectName\\vendor\\symfony\\console\\Application.php(275): Symfony\\Component\\Console\\Application->doRunCommand(Object(Illuminate\\Queue\\Console\\WorkCommand), Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#36 D:\\Xampp\\htdocs\\projectName\\vendor\\symfony\\console\\Application.php(149): Symfony\\Component\\Console\\Application->doRun(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#37 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Console\\Application.php(93): Symfony\\Component\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#38 D:\\Xampp\\htdocs\\projectName\\vendor\\laravel\\framework\\src\\Illuminate\\Foundation\\Console\\Kernel.php(131): Illuminate\\Console\\Application->run(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#39 D:\\Xampp\\htdocs\\projectName\\artisan(37): Illuminate\\Foundation\\Console\\Kernel->handle(Object(Symfony\\Component\\Console\\Input\\ArgvInput), Object(Symfony\\Component\\Console\\Output\\ConsoleOutput))
#40 {main}
"}
Additional information
No response
I don't offer free support for version 5.x anymore,and PHP has been EOL for some years as well.
You could try upgrading at least to version 6 - it's compatible with PHP 7.4 and might fix the issue, but I don't support version 6 anymore as well 😅.
Best would be to upgrade to at least PHP 8.1 and the SDK to 7.x - if the problem still occurs in this version, I can have a look at it.
Alternatively, I can investigate the issue with version 5.x and attempt a fix for a one-time GitHub Sponsors sponsorship of $400. But I really recommend upgrading versions instead
Sorry to bother you jerome, but i tried upgrading to version 6.9 and use the same 7.4 PHP but still get the error.
Is there a way for me to at least see what might be inside the response?
or can you share your latest working dependencies you use for version 6?
I don't use 6.9 (unsupported 😅) anymore, but you can inject loggers into the Factory which then injects it into the HTTP clients:
- https://github.com/kreait/firebase-php/blob/6.9.6/src/Firebase/Factory.php#L216
- https://github.com/kreait/firebase-php/blob/6.9.6/src/Firebase/Factory.php#L228
I must admit I don't remember the difference between the two anymore 🙈