Q:

React-Native fetch not working after NetInfo.isConnected change to true Android

I am working on my React-Native application and I wanted to improve the offline interactions and way it's working.
When the app is loading, we fetch our API in order to display all the needed information. However, when the user is offline, I want to save all the requests in a queue and fire them when the network status change from offline to online.
Even if the fetch is perfectly working when the network status is online at launch, I always have Network request failed when it's offline (normal). But the tricky par is here : even if the NetInfo.isConnected. event Listener detect a change of connection from offline to online, when we re-fired the fetch functions, even is I wait for 10 secondes, always result in Network request failed.
I have no clues why, and I would appreciate some help !
Tested on Android Device in Dev mode && Tested on Android Device in Release mode
Here is the relevant part of the code:
The Fetch Request
const   getLastNotification = () =>
{
    console.log('TRYING TO GET LAST NOTIFICATION')
    return (
        fetch(`${API}/getLastNotification`, {
            method: 'GET',
            headers:
            {
                'Content-Type': 'application/json',
                auth:           AUTHCODE
            }
        })
        .then(async (response) =>
        {
            const   json = await response.json();
            return (json)
        })
        .catch(err => onError(err, () => getLastNotification()))
    );
};

const   onError = (err, func) =>
{
    if (err)
        console.warn(err.message);
    setPendingFetch(func);
};

The Queue
const   PENDING_FETCH = [];

const   getPendingFetch = () => PENDING_FETCH;
const   setPendingFetch = (newFunction) =>
{
    if (!PENDING_FETCH.includes(newFunction))
        PENDING_FETCH.push(newFunction);
};

The Connection Change Handler
handleConnectionChange = (isConnected) =>
{
    console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
    if (isConnected)
    {
        const   allPendingFetch = getPendingFetch();

        setTimeout(() =>
        {
            allPendingFetch.forEach(each => each());
        }, 5000);
    }
}

Even with this kind of handleConnectionChange it's not working
handleConnectionChange = (isConnected) =>
{
    console.log('Then, is ' + (isConnected ? 'online' : 'offline'));
    if (isConnected)
    {
        fetch(`${API}/`, {
            method: 'POST',
            headers: {'Content-Type': 'application/json'}
        })
        .catch(err => console.warn(err.message)) //Network request failed
    }
}

Thank you !
EDIT (in comment)
Okay, after some tests, little update: During 2 minutes after changing the network status to online, the fetch request catch an error (Network request failed) and then, after precisely 2 minutes, the request is working. Nice, but I don't want my users to wait for 2 minutes ... Any idea why ? :)

A:

I found the answer by diving into the Fetch and XMLHttpRequest files.
By displaying some step by step log, I found an error : 'java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.'
To do it simple, it's a SSL certificate error on with the API. If you have the same issue, you can fire this command in the terminal
openssl s_client -debug -connect yourdomain.com:443

And if you have this line in output
Verify return code: 21 (unable to verify the first certificate)

That's probably because of a CRT file misconfigured.
In my case, my provider just send me two files by mail and I had to go to it's website to download all files (3 CRT files), then chain them in the right order (myDomain.crt - AddTrust_External_CA_Root.crt - COMODO_RSA_Certification_Authority.crt) with this command
$ cat myDomain.crt AddTrust_External_CA_Root.crt COMODO_RSA_Certification_Authority.crt > myFinalDomain.crt

And then replace my CRT file on my server by this one.

