Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reconnect was stopped after first-time retry. #26

Open
d2school opened this issue Aug 11, 2023 · 0 comments
Open

Reconnect was stopped after first-time retry. #26

d2school opened this issue Aug 11, 2023 · 0 comments

Comments

@d2school
Copy link

After first time reconnect (retries = 1), and recived a "http-status 500" (or 503, 404 ...), neffos would no try any more reconnect .

file: /src/neffos.js
line : 993:

   let check = (): void => {
        // Note:
        // We do not fire a try immediately after the disconnection as most developers will expect.
        _fetch(endpointHTTP, fetchOptions).then(() => {
            notifyOnline(tries);
        }).catch(() => { // on network failures.
            // if (err !== undefined && err.toString() !== "TypeError: Failed to fetch") {
            //     console.log(err);
            // }
            tries++;
            setTimeout(() => {
                check();
            }, checkEvery)
        });
    };

This would not catch any bad http-status. the new code :

   let check = (): void => {
        // Note:
        // We do not fire a try immediately after the disconnection as most developers will expect.
        _fetch(endpointHTTP, fetchOptions).then((response) => {  // <--- on response
             if (response.ok) {   // on response ok 
                 notifyOnline(tries);
            } else {
                 return Promise.reject(`${response.status}:${response.statusText}`) // <-- reject 
            }
        }).catch((err) => { // on network failures.
            // if (err !== undefined && err.toString() !== "TypeError: Failed to fetch") {
            //     console.log(err);
            // }
            tries++;
            setTimeout(() => {
                check();
            }, checkEvery)
        });
    };

Now, even if the ws-server is restarted after a long time, the ws-client (mneffos.js) can reconnect normally.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant