aerogear / offix

GraphQL Offline Client and Server
https://offix.dev
Apache License 2.0
760 stars 45 forks source link

Error handling with useOfflineMutation hook #373

Closed kingsleyzissou closed 4 years ago

kingsleyzissou commented 4 years ago

Bug Report

The useOfflineMutation doesn't catch server errors. If you wrap the returned runMutation function from the hook in a try/catch block and use async/await, you can catch the server errors. However, offline errors are never resolved or rejected and if the client is offline, the page just hangs until the client comes back online. A potential solution for this is to reject offline errors in the useOfflineMutation hook and handle the offline error on the client, e.g:

...

try {
    ...
    await runMutation();
     ...
} catch(error) {
    if (error.offline) {
     error.watchOfflineChange();
     ...
    }
}

...
kingsleyzissou commented 4 years ago

Fixed with #378