kreait / firebase-php

Unofficial Firebase Admin SDK for PHP
https://firebase-php.readthedocs.io/
MIT License
2.2k stars 422 forks source link

Ambiguous Error message: "Internal Error encountered" #674

Closed fidan-mkdir closed 2 years ago

fidan-mkdir commented 2 years ago

Describe the issue you are experiencing

We've been using this package to successfully send push notifications to Android and iOS devices for a while now but just yesterday an exception was caught by our Sentry. This is what it said:

Kreait\Firebase\Exception\Messaging\ServerError Internal error encountered

As you can see, that is not much to go on. I've looked at a similar issue reported here

355

But I'm not using the topic field at all.

Here is the way I create the notification, note that I have extended the FcmChannel class to account for some custom error handling when there is a NotFound exception, unrelated to this problem anyway.

class FcmChannel extends \NotificationChannels\Fcm\FcmChannel
{
    public function send($notifiable, Notification $notification) {
        $data = $notification->toFcm($notifiable);
        $fcmMessage = FcmMessage::create()
            ->setName($data['title'])
            ->setData($data['data'])
            ->setNotification(\NotificationChannels\Fcm\Resources\Notification::create()
                ->setTitle($data['title'])
                ->setBody($data['message'])
            )
            ->setAndroid(
                AndroidConfig::create()
                    ->setFcmOptions(AndroidFcmOptions::create()->setAnalyticsLabel('analytics_android'))
            )->setApns(
                ApnsConfig::create()
                    ->setHeaders([
                        'push-type' => 'background'
                    ])
                    ->setPayload([
                        'aps' => [
                            'content-available' => 1
                        ]
                    ])
                    ->setFcmOptions(ApnsFcmOptions::create()->setAnalyticsLabel('analytics_ios'))
            );

        $token = $notifiable->routeNotificationFor('fcm', $notification);

        if (empty($token)) {
            return [];
        }

        $this->fcmProject = null;
        if (method_exists($notification, 'fcmProject')) {
            $this->fcmProject = $notification->fcmProject($notifiable, $fcmMessage);
        }

        $responses = [];

        try {
            if (is_array($token)) {
                // Use multicast when there are multiple recipients
                $partialTokens = array_chunk($token, self::MAX_TOKEN_PER_REQUEST);
                foreach ($partialTokens as $tokens) {
                    $responses[] = $this->sendToFcmMulticast($fcmMessage, $tokens);
                }
            } else {
                $responses[] = $this->sendToFcm($fcmMessage, $token);
            }
        } catch (\Kreait\Firebase\Exception\Messaging\NotFound $exception) {
            if ($notifiable instanceof User) {
                /* @var $notifiable User */
                $notifiable->unset('fcm_token');
                $notifiable->save();
            }

            \Log::channel('notification_log')->info('[Invalid FCM Token] Removed FCM token from user: ' . $notifiable->full_name . '[' . $notifiable->id . ']');

            $this->failedNotification($notifiable, $notification, $exception); // dispatches failed notification event
        } catch (MessagingException $exception) {
            $this->failedNotification($notifiable, $notification, $exception);
            throw CouldNotSendNotification::serviceRespondedWithAnError($exception);
        }

        return $responses;
    }
}

Has anyone had a similar issue? I'm really using FCM for simple text messages, so there is nothing additional.

Installed packages

asm89/stack-cors                          v2.0.3  Cross-origin resource sharing library and stack middleware
aws/aws-sdk-php                           3.191.2 AWS SDK for PHP - Use Amazon Web Services in your PHP project
bretterer/iso_duration_converter          v0.1.0  Easily convert ISO_8601 Duration time format to seconds and conve...
brick/math                                0.9.3   Arbitrary-precision arithmetic library
cbschuld/browser.php                      v1.9.6  A PHP Class to detect a user's Browser.  This encapsulation provi...
clue/stream-filter                        v1.5.0  A simple and modern approach to stream filtering in PHP
darkaonline/l5-swagger                    8.0.7   OpenApi or Swagger integration to Laravel
doctrine/annotations                      1.13.2  Docblock Annotations Parser
doctrine/inflector                        2.0.3   PHP Doctrine Inflector is a small library that can perform string...
doctrine/instantiator                     1.4.0   A small, lightweight utility to instantiate objects in PHP withou...
doctrine/lexer                            1.2.1   PHP Doctrine Lexer parser library that can be used in Top-Down, R...
dragonmantank/cron-expression             v3.1.0  CRON for PHP: Calculate the next or previous run date and determi...
egulias/email-validator                   2.1.25  A library for validating emails against several RFCs
facade/flare-client-php                   1.8.1   Send PHP errors to Flare
facade/ignition                           2.12.0  A beautiful error page for Laravel applications.
facade/ignition-contracts                 1.0.2   Solution contracts for Ignition
fakerphp/faker                            v1.15.0 Faker is a PHP library that generates fake data for you.
fideloper/proxy                           4.4.1   Set trusted proxies for Laravel
fig/http-message-util                     1.1.5   Utility classes and constants for use with PSR-7 (psr/http-message)
filp/whoops                               2.14.0  php error handling for cool kids
firebase/php-jwt                          v5.4.0  A simple library to encode and decode JSON Web Tokens (JWT) in PH...
fruitcake/laravel-cors                    v2.0.4  Adds CORS (Cross-Origin Resource Sharing) headers support in your...
google/auth                               v1.17.0 Google Auth Library for PHP
google/cloud-core                         v1.42.2 Google Cloud PHP shared dependency, providing functionality usefu...
google/cloud-storage                      v1.24.1 Cloud Storage Client for PHP
google/crc32                              v0.1.0  Various CRC32 implementations
graham-campbell/result-type               v1.0.1  An Implementation Of The Result Type
guzzlehttp/guzzle                         7.3.0   Guzzle is a PHP HTTP client library
guzzlehttp/promises                       1.4.1   Guzzle promises library
guzzlehttp/psr7                           1.8.2   PSR-7 message implementation that also provides common utility me...
hamcrest/hamcrest-php                     v2.0.1  This is the PHP port of Hamcrest Matchers
http-interop/http-factory-guzzle          1.2.0   An HTTP Factory using Guzzle PSR7
jean85/pretty-package-versions            2.0.4   A library to get pretty versions strings of installed dependencies
jenssegers/mongodb                        3.8.4   A MongoDB based Eloquent model and Query builder for Laravel (Mol...
kreait/clock                              1.1.0   A PHP 7.0 compatible clock abstraction
kreait/firebase-php                       5.19.0  Firebase Admin SDK
kreait/firebase-tokens                    1.15.0  A library to work with Firebase tokens
kreait/laravel-firebase                   3.1.0   A Laravel package for the Firebase PHP Admin SDK
laravel-notification-channels/fcm         2.2.1   FCM (Firebase Cloud Messaging) Notifications Driver for Laravel
laravel/framework                         v8.57.0 The Laravel Framework.
laravel/helpers                           v1.4.1  Provides backwards compatibility for helpers in the latest Larave...
laravel/socialite                         v5.2.4  Laravel wrapper around OAuth 1 & OAuth 2 libraries.
laravel/tinker                            v2.6.1  Powerful REPL for the Laravel framework.
laravel/ui                                v3.3.0  Laravel UI utilities and presets.
lcobucci/jwt                              3.4.5   A simple library to work with JSON Web Token and JSON Web Signature
league/commonmark                         1.6.6   Highly-extensible PHP Markdown parser which fully supports the Co...
league/flysystem                          1.1.5   Filesystem abstraction: Many filesystems, one API.
league/flysystem-aws-s3-v3                1.0.29  Flysystem adapter for the AWS S3 SDK v3.x
league/mime-type-detection                1.7.0   Mime-type detection for Flysystem
league/oauth1-client                      v1.10.0 OAuth 1.0 Client Library
mockery/mockery                           1.4.3   Mockery is a simple yet flexible PHP mock object framework
mongodb/mongodb                           1.9.0   MongoDB driver library
monolog/monolog                           2.3.2   Sends your logs to files, sockets, inboxes, databases and various...
mtdowling/jmespath.php                    2.6.1   Declaratively specify how to extract elements from a JSON document
myclabs/deep-copy                         1.10.2  Create deep copies (clones) of your objects
nesbot/carbon                             2.52.0  An API extension for DateTime that supports 281 different languages.
nikic/php-parser                          v4.12.0 A PHP parser written in PHP
nunomaduro/collision                      v5.8.0  Cli error handling for console/command-line PHP applications.
nyholm/psr7                               1.4.1   A fast PHP7 implementation of PSR-7
okta/jwt-verifier                         1.1.1   A verifier library for working with Okta JWT's
opis/closure                              3.6.2   A library that can be used to serialize closures (anonymous funct...
phar-io/manifest                          2.0.3   Component for reading phar.io manifest information from a PHP Arc...
phar-io/version                           3.1.0   Library for handling version information and constraints
php-http/client-common                    2.4.0   Common HTTP Client implementations and tools for HTTPlug
php-http/curl-client                      2.2.0   PSR-18 and HTTPlug Async client with cURL
php-http/discovery                        1.14.0  Finds installed HTTPlug implementations and PSR-7 message factories
php-http/httplug                          2.2.0   HTTPlug, the HTTP client abstraction for PHP
php-http/message                          1.11.2  HTTP Message related tools
php-http/message-factory                  v1.0.2  Factory interfaces for PSR-7 HTTP Message
php-http/promise                          1.1.0   Promise used for asynchronous HTTP requests
php-parallel-lint/php-console-color       v0.3
php-parallel-lint/php-console-highlighter v0.5    Highlight PHP code in terminal
phpdocumentor/reflection-common           2.2.0   Common reflection classes used by phpdocumentor to reflect the co...
phpdocumentor/reflection-docblock         5.2.2   With this component, a library can provide support for annotation...
phpdocumentor/type-resolver               1.4.0   A PSR-5 based resolver of Class names, Types and Structural Eleme...
phpoption/phpoption                       1.7.5   Option Type for PHP
phpspec/prophecy                          1.13.0  Highly opinionated mocking framework for PHP 5.3+
phpunit/php-code-coverage                 9.2.6   Library that provides collection, processing, and rendering funct...
phpunit/php-file-iterator                 3.0.5   FilterIterator implementation that filters files based on a list ...
phpunit/php-invoker                       3.1.1   Invoke callables with a timeout
phpunit/php-text-template                 2.0.4   Simple template engine.
phpunit/php-timer                         5.0.3   Utility class for timing
phpunit/phpunit                           9.5.8   The PHP Unit Testing framework.
predis/predis                             v1.1.7  Flexible and feature-complete Redis client for PHP and HHVM
psr/cache                                 1.0.1   Common interface for caching libraries
psr/container                             1.1.1   Common Container Interface (PHP FIG PSR-11)
psr/event-dispatcher                      1.0.0   Standard interfaces for event handling.
psr/http-client                           1.0.1   Common interface for HTTP clients
psr/http-factory                          1.0.1   Common interfaces for PSR-7 HTTP message factories
psr/http-message                          1.0.1   Common interface for HTTP messages
psr/log                                   1.1.4   Common interface for logging libraries
psr/simple-cache                          1.0.1   Common interfaces for simple caching
psy/psysh                                 v0.10.8 An interactive shell for modern PHP.
ralouphie/getallheaders                   3.0.3   A polyfill for getallheaders.
ramsey/collection                         1.2.1   A PHP library for representing and manipulating collections.
ramsey/uuid                               4.2.1   A PHP library for generating and working with universally unique ...
riverline/multipart-parser                2.0.8   One class library to parse multipart content with encoding and ch...
rize/uri-template                         0.3.3   PHP URI Template (RFC 6570) supports both expansion & extraction
sebastian/cli-parser                      1.0.1   Library for parsing CLI options
sebastian/code-unit                       1.0.8   Collection of value objects that represent the PHP code units
sebastian/code-unit-reverse-lookup        2.0.3   Looks up which function or method a line of code belongs to
sebastian/comparator                      4.0.6   Provides the functionality to compare PHP values for equality
sebastian/complexity                      2.0.2   Library for calculating the complexity of PHP code units
sebastian/diff                            4.0.4   Diff implementation
sebastian/environment                     5.1.3   Provides functionality to handle HHVM/PHP environments
sebastian/exporter                        4.0.3   Provides the functionality to export PHP variables for visualization
sebastian/global-state                    5.0.3   Snapshotting of global state
sebastian/lines-of-code                   1.0.3   Library for counting the lines of code in PHP source code
sebastian/object-enumerator               4.0.4   Traverses array structures and object graphs to enumerate all ref...
sebastian/object-reflector                2.0.4   Allows reflection of object attributes, including inherited and n...
sebastian/recursion-context               4.0.4   Provides functionality to recursively process PHP variables
sebastian/resource-operations             3.0.3   Provides a list of PHP built-in functions that operate on resources
sebastian/type                            2.3.4   Collection of value objects that represent the types of the PHP t...
sebastian/version                         3.0.2   Library that helps with managing the version number of Git-hosted...
sentry/sdk                                3.1.0   This is a metapackage shipping sentry/sentry with a recommended H...
sentry/sentry                             3.3.2   A PHP SDK for Sentry (http://sentry.io)
sentry/sentry-laravel                     2.8.0   Laravel SDK for Sentry (https://sentry.io)
socialiteproviders/manager                4.0.1   Easily add new or override built-in providers in Laravel Socialite.
socialiteproviders/okta                   4.1.1   Okta OAuth2 Provider for Laravel Socialite
spatie/enum                               2.3.8   PHP Enums
swagger-api/swagger-ui                    v3.52.0  Swagger UI is a collection of HTML, Javascript, and CSS assets t...
swiftmailer/swiftmailer                   v6.2.7  Swiftmailer, free feature-rich PHP mailer
symfony/console                           v5.3.6  Eases the creation of beautiful and testable command line interfaces
symfony/css-selector                      v5.3.4  Converts CSS selectors to XPath expressions
symfony/deprecation-contracts             v2.4.0  A generic function and convention to trigger deprecation notices
symfony/error-handler                     v5.3.4  Provides tools to manage errors and ease debugging PHP code
symfony/event-dispatcher                  v5.3.4  Provides tools that allow your application components to communic...
symfony/event-dispatcher-contracts        v2.4.0  Generic abstractions related to dispatching event
symfony/finder                            v5.3.4  Finds files and directories via an intuitive fluent interface
symfony/http-client                       v5.3.4  Provides powerful methods to fetch HTTP resources synchronously o...
symfony/http-client-contracts             v2.4.0  Generic abstractions related to HTTP clients
symfony/http-foundation                   v5.3.6  Defines an object-oriented layer for the HTTP specification
symfony/http-kernel                       v5.3.6  Provides a structured process for converting a Request into a Res...
symfony/mime                              v5.3.4  Allows manipulating MIME messages
symfony/options-resolver                  v5.3.4  Provides an improved replacement for the array_replace PHP function
symfony/polyfill-ctype                    v1.23.0 Symfony polyfill for ctype functions
symfony/polyfill-iconv                    v1.23.0 Symfony polyfill for the Iconv extension
symfony/polyfill-intl-grapheme            v1.23.1 Symfony polyfill for intl's grapheme_* functions
symfony/polyfill-intl-idn                 v1.23.0 Symfony polyfill for intl's idn_to_ascii and idn_to_utf8 functions
symfony/polyfill-intl-normalizer          v1.23.0 Symfony polyfill for intl's Normalizer class and related functions
symfony/polyfill-mbstring                 v1.23.1 Symfony polyfill for the Mbstring extension
symfony/polyfill-php72                    v1.23.0 Symfony polyfill backporting some PHP 7.2+ features to lower PHP ...
symfony/polyfill-php73                    v1.23.0 Symfony polyfill backporting some PHP 7.3+ features to lower PHP ...
symfony/polyfill-php80                    v1.23.1 Symfony polyfill backporting some PHP 8.0+ features to lower PHP ...
symfony/polyfill-php81                    v1.23.0 Symfony polyfill backporting some PHP 8.1+ features to lower PHP ...
symfony/polyfill-uuid                     v1.23.0 Symfony polyfill for uuid functions
symfony/process                           v5.3.4  Executes commands in sub-processes
symfony/psr-http-message-bridge           v2.1.1  PSR HTTP message bridge
symfony/routing                           v5.3.4  Maps an HTTP request to a set of configuration variables
symfony/service-contracts                 v2.4.0  Generic abstractions related to writing services
symfony/string                            v5.3.3  Provides an object-oriented API to strings and deals with bytes, ...
symfony/translation                       v5.3.4  Provides tools to internationalize your application
symfony/translation-contracts             v2.4.0  Generic abstractions related to translation
symfony/var-dumper                        v5.3.6  Provides mechanisms for walking through any arbitrary PHP variable
symfony/yaml                              v5.3.6  Loads and dumps YAML files
theseer/tokenizer                         1.2.1   A small library for converting tokenized PHP source code into XML...
tijsverkoyen/css-to-inline-styles         2.2.3   CssToInlineStyles is a class that enables you to convert HTML-pag...
timacdonald/log-fake                      1.9.0   A drop in fake logger for testing with the Laravel framework.
twilio/sdk                                6.28.0  A PHP wrapper for Twilio's API
vlucas/phpdotenv                          v5.3.0  Loads environment variables from `.env` to `getenv()`, `$_ENV` an...
voku/portable-ascii                       1.5.6   Portable ASCII library - performance optimized (ascii) string fun...
webmozart/assert                          1.10.0  Assertions to validate method input/output with nice error messages.
zircote/swagger-php                       3.2.3   swagger-php - Generate interactive documentation for your RESTful...

PHP version and extension

7.3

On which operating system(s) does the issue occur?

Steps to reproduce the issue.

Honestly, I do not know.

Error message/Stack trace

Kreait\Firebase\Exception\Messaging\ServerError: Internal error encountered.
#72 /vendor/kreait/firebase-php/src/Firebase/Exception/Messaging/ServerError.php(22): Kreait\Firebase\Exception\Messaging\ServerError::withErrors
#71 /vendor/kreait/firebase-php/src/Firebase/Exception/MessagingApiExceptionConverter.php(112): Kreait\Firebase\Exception\MessagingApiExceptionConverter::convertResponse
#70 /vendor/kreait/firebase-php/src/Firebase/Exception/MessagingApiExceptionConverter.php(120): Kreait\Firebase\Exception\MessagingApiExceptionConverter::convertGuzzleRequestException
#69 /vendor/kreait/firebase-php/src/Firebase/Exception/MessagingApiExceptionConverter.php(49): Kreait\Firebase\Exception\MessagingApiExceptionConverter::convertException
#68 /vendor/kreait/firebase-php/src/Firebase/Messaging/ApiClient.php(44): Kreait\Firebase\Messaging\ApiClient::send
#67 /vendor/kreait/firebase-php/src/Firebase/Messaging.php(54): Kreait\Firebase\Messaging::send
#66 /vendor/laravel-notification-channels/fcm/src/FcmChannel.php(123): NotificationChannels\Fcm\FcmChannel::sendToFcm
#65 /app/Channels/FcmChannel.php(63): App\Channels\FcmChannel::send
#64 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(148): Illuminate\Notifications\NotificationSender::sendToNotifiable
#63 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(106): Illuminate\Notifications\NotificationSender::Illuminate\Notifications\{closure}
#62 /vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\Notifications\NotificationSender::withLocale
#61 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(109): Illuminate\Notifications\NotificationSender::sendNow
#60 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(79): Illuminate\Notifications\NotificationSender::send
#59 /vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php(39): Illuminate\Notifications\ChannelManager::send
#58 /vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php(18): App\Models\User::notify
#57 /app/Models/ShiftOffer.php(106): App\Models\ShiftOffer::notifyUser
#56 /app/Repos/RequestFormRepository.php(470): App\Repos\RequestFormRepository::offer_shift_to_user
#55 /app/Http/Controllers/ShiftRequestController.php(62): App\Http\Controllers\ShiftRequestController::offerShift
#54 /vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Illuminate\Routing\Controller::callAction
#53 /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\ControllerDispatcher::dispatch
#52 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\Route::runController
#51 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route::run
#50 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Routing\Router::Illuminate\Routing\{closure}
#49 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#48 /app/Http/Middleware/CheckOktaTokenForWeb.php(27): App\Http\Middleware\CheckOktaTokenForWeb::handle
#47 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#46 /vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Routing\Middleware\SubstituteBindings::handle
#45 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#44 /vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Auth\Middleware\Authenticate::handle
#43 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#42 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle
#41 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#40 /vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\View\Middleware\ShareErrorsFromSession::handle
#39 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#38 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Session\Middleware\StartSession::handleStatefulRequest
#37 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession::handle
#36 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#35 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle
#34 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#33 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Cookie\Middleware\EncryptCookies::handle
#32 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#31 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#30 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\Routing\Router::runRouteWithinStack
#29 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\Routing\Router::runRoute
#28 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router::dispatchToRoute
#27 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router::dispatch
#26 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http\{closure}
#25 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#24 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Sentry\Laravel\Http\SetRequestIpMiddleware::handle
#23 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#22 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(42): Sentry\Laravel\Http\SetRequestMiddleware::handle
#21 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#20 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Session\Middleware\StartSession::handleStatefulRequest
#19 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession::handle
#18 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#17 /app/Http/Middleware/ElasticBeanstalkHttps.php(25): App\Http\Middleware\ElasticBeanstalkHttps::handle
#16 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#15 /vendor/fideloper/proxy/src/TrustProxies.php(57): Fideloper\Proxy\TrustProxies::handle
#14 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#13 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#12 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle
#11 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#10 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#9 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TrimStrings::handle
#8 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#7 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle
#6 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#5 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::handle
#4 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#3 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#2 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Foundation\Http\Kernel::sendRequestThroughRouter
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel::handle
#0 /public/index.php(55): null
NotificationChannels\Fcm\Exceptions\CouldNotSendNotification: Internal error encountered.
#66 /vendor/laravel-notification-channels/fcm/src/Exceptions/CouldNotSendNotification.php(13): NotificationChannels\Fcm\Exceptions\CouldNotSendNotification::serviceRespondedWithAnError
#65 /app/Channels/FcmChannel.php(77): App\Channels\FcmChannel::send
#64 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(148): Illuminate\Notifications\NotificationSender::sendToNotifiable
#63 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(106): Illuminate\Notifications\NotificationSender::Illuminate\Notifications\{closure}
#62 /vendor/laravel/framework/src/Illuminate/Support/Traits/Localizable.php(19): Illuminate\Notifications\NotificationSender::withLocale
#61 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(109): Illuminate\Notifications\NotificationSender::sendNow
#60 /vendor/laravel/framework/src/Illuminate/Notifications/NotificationSender.php(79): Illuminate\Notifications\NotificationSender::send
#59 /vendor/laravel/framework/src/Illuminate/Notifications/ChannelManager.php(39): Illuminate\Notifications\ChannelManager::send
#58 /vendor/laravel/framework/src/Illuminate/Notifications/RoutesNotifications.php(18): App\Models\User::notify
#57 /app/Models/ShiftOffer.php(106): App\Models\ShiftOffer::notifyUser
#56 /app/Repos/RequestFormRepository.php(470): App\Repos\RequestFormRepository::offer_shift_to_user
#55 /app/Http/Controllers/ShiftRequestController.php(62): App\Http\Controllers\ShiftRequestController::offerShift
#54 /vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): Illuminate\Routing\Controller::callAction
#53 /vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\ControllerDispatcher::dispatch
#52 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\Route::runController
#51 /vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route::run
#50 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(695): Illuminate\Routing\Router::Illuminate\Routing\{closure}
#49 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#48 /app/Http/Middleware/CheckOktaTokenForWeb.php(27): App\Http\Middleware\CheckOktaTokenForWeb::handle
#47 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#46 /vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Routing\Middleware\SubstituteBindings::handle
#45 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#44 /vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Auth\Middleware\Authenticate::handle
#43 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#42 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle
#41 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#40 /vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\View\Middleware\ShareErrorsFromSession::handle
#39 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#38 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Session\Middleware\StartSession::handleStatefulRequest
#37 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession::handle
#36 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#35 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle
#34 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#33 /vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Cookie\Middleware\EncryptCookies::handle
#32 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#31 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#30 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(697): Illuminate\Routing\Router::runRouteWithinStack
#29 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(672): Illuminate\Routing\Router::runRoute
#28 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(636): Illuminate\Routing\Router::dispatchToRoute
#27 /vendor/laravel/framework/src/Illuminate/Routing/Router.php(625): Illuminate\Routing\Router::dispatch
#26 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http\{closure}
#25 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#24 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestIpMiddleware.php(45): Sentry\Laravel\Http\SetRequestIpMiddleware::handle
#23 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#22 /vendor/sentry/sentry-laravel/src/Sentry/Laravel/Http/SetRequestMiddleware.php(42): Sentry\Laravel\Http\SetRequestMiddleware::handle
#21 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#20 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Session\Middleware\StartSession::handleStatefulRequest
#19 /vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession::handle
#18 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#17 /app/Http/Middleware/ElasticBeanstalkHttps.php(25): App\Http\Middleware\ElasticBeanstalkHttps::handle
#16 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#15 /vendor/fideloper/proxy/src/TrustProxies.php(57): Fideloper\Proxy\TrustProxies::handle
#14 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#13 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#12 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle
#11 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#10 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Foundation\Http\Middleware\TransformsRequest::handle
#9 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TrimStrings::handle
#8 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#7 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle
#6 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#5 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::handle
#4 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure}
#3 /vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline::then
#2 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Foundation\Http\Kernel::sendRequestThroughRouter
#1 /vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel::handle
#0 /public/index.php(55): null

Additional information

No response

jeromegamez commented 2 years ago

Unfortunately, the fact that it used to be working in the past and then stopped working, suggests that the problem is on the Firebase server. The ambiguous message Internal error occurred is the message that the server sends back, so there is not really something that can be done to make it less ambiguous 😅.

As for your code - it seems to be catered to the laravel-notification-channels/fcm so I can't assist you with it, but again, if it used to work, that's probably not the problem, but if you want me to have a look at it, please provide me with the payload just before it is sent to the Firebase servers (you could, for example, temporarily put an echo (string) $request->getBody() into https://github.com/kreait/firebase-php/blob/94cc2699471896ec36ff9abe86af4263d10c45c6/src/Firebase/Messaging/ApiClient.php#L39-L46

Perhaps I can then see something in the payload if it stands out to me. Hopefully, it's really just a problem on the server side and it will correct itself in time 🤞

jeromegamez commented 2 years ago

I was noticing the same problem when running the integration tests of the SDK with a test registration token that I had generated by the end of October (I'm using https://github.com/firebase/quickstart-js/tree/master/messaging to manually generate an FCM registration token and inject it into the tests via an environment variable).

Once I generated a new FCM token, the tests worked again. Are you by any chance using a pre-generated test FCM token as well?

I'm not sure why Firebase (the server) is returning the Internal Server Error here, but it seems as if it has something to do with too old FCM device tokens. Could you try again with another, freshly created FCM token?

fidan-mkdir commented 2 years ago

We generate a token when the user accesses the mobile version of the app, as it is primarily a web app, with some of the functionality now enabled through a mobile app.

The token is updated in the web app database every time a user logs on the mobile app and is deleted when they log out from the mobile app. However, this doesn't mean that it is a fresh token every time the user logs in the mobile app, but there is a handler that ensures that the token is updated in the mobile app when it is refreshed. Is this bad practice? Should we refresh the token every time the user uses the app? Occasionally, we get a not found error (because of an invalid FCM token) and that is the part in which we remove the FCM token from the user until they log in again.

The interesting part is that this issue occurred only once, so I can't exactly give you a payload of a failed message. Would a regular payload be able to shed some light?

Dump:

{
   "message":{
      "name":"Shift Offer",
      "data":{
         "shift_offer_id":"some_id_here",
         "shift_request_id":"other_id_here",
         "type":"shift_offer"
      },
      "notification":{
         "title":"Shift Offer",
         "body":"A shift is available at Location, Room on Date Time.",
         "image":null
      },
      "android":{
         "collapse_key":null,
         "priority":null,
         "ttl":null,
         "restricted_package_name":null,
         "data":null,
         "notification":null,
         "fcm_options":{
            "analytics_label":"analytics_android"
         }
      },
      "webpush":null,
      "apns":{
         "headers":{
            "push-type":"background"
         },
         "payload":{
            "aps":{
               "content-available":1
            }
         },
         "fcm_options":{
            "analytics_label":"analytics_ios",
            "image":null
         }
      },
      "fcm_options":null,
      "token":"token_printed_here",
      "topic":null,
      "condition":null
   },
   "validate_only":false
}
jeromegamez commented 2 years ago

Thank you for providing further details, mainly that the problem has occurred only once so far. Please don't think that I want to make it too easy on myself, but I believe that this "Internal Server error" could/should be something that you treat as if the FCM token had not been found, and let your web/mobile app send register a new one and send it back to your PHP application.

try {
    // send the message
} catch (\Kreait\Firebase\Exception\Messaging\NotFound $exception) {
    // The token was not found = it has been unregistered on the Firebase servers
    // Let the client/mobile app send us a new one
} catch (\Kreait\Firebase\Exception\Messaging\ServerError $exception) {
    // The Firebase Servers responded with a 500 error
    // Why? Only Firebase knows, but it happens from time to time. This can usually
    // be solved by letting the client request a new registration (same behavior as NotFound)
} catch (MessagingException $exception) {
    // Something else went wrong
}

I'm sorry I can't provide a more satisfying answer - I didn't dare let the SDK automatically treat 500 errors as if they were 404 errors, even though it seems to be that way. I haven't found out yet, when those errors are triggered, only that I encounter them from time to time myself, and regenerating the FCM token helps each time.

Since we're both encountering them with a web application involved, I'd guess that it might have something to do with browser updates, or changed extensions, or even notification settings. Still, it's just me speculating here.

fidan-mkdir commented 2 years ago

Okay, sounds like it is best to just treat this as an invalid FCM token case and remove it from the user, then the mobile app will automatically replace it with a new one.

Thank you very much for looking into this, it is much appreciated.

jeromegamez commented 2 years ago

You're welcome! 🌺 I'm going to close the issue because (at the moment) it doesn't seem as if this can be handled from within the SDK, but you can of course add comments in case your investigation revealed something new! Thanks!

gbrits commented 8 months ago

In my case, this occurred whenever the Ionic 7 Capacitor 5 AngularJS app I had open was closed when the push notification was issued.

If the app is running - no error, if the app is closed, Internal Error encountered error.

Here is my Laravel notification code:

<?php

namespace App\Notifications;

use Illuminate\Notifications\Notification;
use NotificationChannels\Fcm\FcmChannel;
use NotificationChannels\Fcm\FcmMessage;
use NotificationChannels\Fcm\Resources\Notification as FcmNotification;

class RequestAccess extends Notification
{
    public $url_string;
    public $asset_id;
    public $first_name;
    public $last_name;
    public $email;
    public $company;

    public function __construct($url_string, etc...)
    {
        $this->url_string = $url_string;
       ... // etc
    }

    public function via($notifiable)
    {
        return [FcmChannel::class];
    }

    public function toFcm($notifiable)
    {
        return (new FcmMessage())
            ->setData([
                'url_string' => $this->url_string ?? '',
                ... // etc.
            ])->setNotification(
                FcmNotification::create()
                    ->setTitle('Access Request')
                    ->setBody('You have a new access request')
            );
    }
}

Obviously I need the push notifications to fire even when the app is closed, any clues on this are appreciated, thank you.

jeromegamez commented 8 months ago

Your code indicates that you are using the Laravel FCM notification channel package, which I don't maintain.

The library uses version 5.x of the SDK which has reached EOL and which I therefore don't support anymore (the current version is 7.x).

For these two reasons I can't provide you with in-depth support.

However, the Internal Server Error is returned by the Firebase Servers. I don't know how this relates to your app being opened or closed, but this is handling by Firebase, and can't be fixed from within the SDK.

gbrits commented 8 months ago

Thanks for the courtesy response @jeromegamez - apologies for re-opening a closed thread that doesn't particularly pertain to your library. For the record, in order to hopefully help someone else encountering something similar, I upgraded my project to PHP 8.2 and upgraded my laravel-notification-channels/fcm library to ^4.0 which released last week. It appears it still uses the 5.x SDK, but the error I was encountering (app being closed when a push is received) no longer resulted in the error I had before, so something was rectified in the midst of all the assorted PHP jumps & the channel package bump.

So thanks for the nudge in the upgrade direction. :)

jeromegamez commented 8 months ago

I'm glad I could help at least a little, even if just indirectly 😅, and thank you for sharing how you got it sorted out, I'm sure it will help someone!