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

Feedback: How to handle offline use appropriately with network errors? #6172

Closed
MrChadMWood opened this issue Jul 1, 2024 · 4 comments
Closed

Comments

@MrChadMWood
Copy link

I am testing an application's stability while offline and everything works great, though the console gets filled with errors like shown at the bottom of this issue.

Is there a way to catch the network errors and, maybe just display a banner to the user when they are offline?
I did attempt to catch any errors within the push handler, like so:

const createPushHandler = (endpoint) => async (changeRows) => {
    try {
        const rawResponse = await fetch(`${endpoint}/push`, {
            method: 'POST',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(changeRows)
        });

        if (!rawResponse.ok) {
            throw new Error('Failed to push changes to the server');
        }

        return await rawResponse.json();
    } catch (error) {
        console.error('Error pushing changes to server:', error);
    }
};

My attempt does not work though, as I am still receiving the RxError (RC_PUSH_NO_AR). Error below:

15:52:02.064 Replication Error: RxError (RC_PUSH_NO_AR): RxError (RC_PUSH_NO_AR):
RxReplication push handler did not return an array with the conflicts
 You can find out more about this error here: https://rxdb.info/errors.html?console=errors#RC_PUSH_NO_AR 
Given parameters: {
pushRows:[
  {
    "assumedMasterState": {
      "updated_at": "2024-06-19T17:52:48.099070Z",
      "_deleted": false
    },
    "newDocumentState": {
      "updated_at": "2024-06-19T17:52:48.099070Z",
      "_deleted": false
    }
  }
]
direction:"push"
args:{
  "result": null
}}
    Babel 2
    RxError rx-error.ts:63
    newRxError rx-error.ts:125
    masterWrite index.ts:312
Copy link

stale bot commented Jul 9, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

@stale stale bot added the stale label Jul 9, 2024
@pubkey
Copy link
Owner

pubkey commented Jul 9, 2024

The push- and pull handlers will be retried until they no longer error. If you want to pause that, return a promise that does not resolve until the user does something.

@stale stale bot removed the stale label Jul 9, 2024
@sagark1235
Copy link

sagark1235 commented Jul 16, 2024

Hi guys I am facing the same issue with the push replication although my data is getting pushed but getting this error and I think because of this only one (first record is getting pushed to the server). What to do any suggestion please.

Copy link

stale bot commented Jul 23, 2024

This issue has been automatically marked as stale because it has not had recent activity. It will be closed soon. Please update it or it may be closed to keep our repository organized. The best way is to add some more information or make a pull request with a test case. Also you might get help in fixing it at the RxDB Community Chat If you know you will continue working on this, just write any message to the issue (like "ping") to remove the stale tag.

@pubkey pubkey closed this as completed Jul 23, 2024
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

3 participants