The work around I have used in my project is like this.
Amplify Version: "aws-amplify": "^3.3.8"
- First listen for the error by below code
Amplify.configure({
.....
....
}
});
analyticServiceErrorHandler();
analyticServiceErrorHandler() {
Hub.listen('analytics', data => {
Analytics.updateEndpoint({ immediate: true })
.then(resp => {
// Analytics service configured and connected properly
})
.catch(e => {
// Analytics service is not connected
// Try Clearing Pinpoint endpoint stored in local storage
clearCachedEndPoints();
}
});
});
}
- Clear cached Endpoints manually
private clearCachedEndPoints() {
const allKeys = Object.entries(localStorage);
console.log('Clearing keys');
const keysToClear = allKeys.filter(
x => x[0].indexOf('aws-amplify-cacheAWSPinpoint') > -1 || x[0].indexOf('CognitoIdentityId') > -1 || x[0].indexOf('aws-amplify-cacheCurSize') > -1
);
keysToClear.forEach(x => {
if (x[0]) {
localStorage.removeItem(x[0]);
console.log('Clearing key', x[0]);
}
});
}
- Third step is up to you, how you want handle the re-initializing the analytic configuration, one option is to refresh the page (warning: this approach may lead to many page refresh in case something else went wrong) and it will start working, second try to re configure using method, or may be let it be the way it is on next client visit to page it will work as page refresh.
Hope this will help.
Top comments (0)