MOBILE-3909 core: Fix unregister device if token is expired
parent
e86d49742a
commit
55a3c0539c
|
@ -591,8 +591,7 @@ export class CoreSite {
|
|||
|
||||
return response;
|
||||
} catch (error) {
|
||||
if (error.errorcode == 'invalidtoken' ||
|
||||
(error.errorcode == 'accessexception' && error.message.indexOf('Invalid token - token expired') > -1)) {
|
||||
if (CoreUtils.isExpiredTokenError(error)) {
|
||||
if (initialToken !== this.token && !retrying) {
|
||||
// Token has changed, retry with the new token.
|
||||
preSets.getFromCache = false; // Don't check cache now. Also, it will skip ongoingRequests.
|
||||
|
|
|
@ -524,7 +524,13 @@ export class CorePushNotificationsProvider {
|
|||
try {
|
||||
response = await site.write<CoreUserRemoveUserDeviceWSResponse>('core_user_remove_user_device', data);
|
||||
} catch (error) {
|
||||
if (CoreUtils.isWebServiceError(error)) {
|
||||
if (CoreUtils.isWebServiceError(error) || CoreUtils.isExpiredTokenError(error)) {
|
||||
// Cannot unregister. Don't try again.
|
||||
await CoreUtils.ignoreErrors(db.deleteRecords(PENDING_UNREGISTER_TABLE_NAME, {
|
||||
token: site.getToken(),
|
||||
siteid: site.getId(),
|
||||
}));
|
||||
|
||||
throw error;
|
||||
}
|
||||
|
||||
|
|
|
@ -850,7 +850,7 @@ export class CoreUtilsProvider {
|
|||
}
|
||||
|
||||
/**
|
||||
* Given an error returned by a WS call, check if the error is generated by the app or it has been returned by the WebSwervice.
|
||||
* Given an error returned by a WS call, check if the error is generated by the app or it has been returned by the WebService.
|
||||
*
|
||||
* @param error Error to check.
|
||||
* @return Whether the error was returned by the WebService.
|
||||
|
@ -858,10 +858,22 @@ export class CoreUtilsProvider {
|
|||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
isWebServiceError(error: any): boolean {
|
||||
return error && (typeof error.warningcode != 'undefined' || (typeof error.errorcode != 'undefined' &&
|
||||
error.errorcode != 'invalidtoken' && error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||
error.errorcode != 'userdeleted' && error.errorcode != 'upgraderunning' &&
|
||||
error.errorcode != 'forcepasswordchangenotice' && error.errorcode != 'usernotfullysetup' &&
|
||||
error.errorcode != 'sitepolicynotagreed' && error.errorcode != 'sitemaintenance' &&
|
||||
(error.errorcode != 'accessexception' || error.message.indexOf('Invalid token - token expired') == -1)));
|
||||
!this.isExpiredTokenError(error)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an error returned by a WS call, check if the error is a token expired error.
|
||||
*
|
||||
* @param error Error to check.
|
||||
* @return Whether the error is a token expired error.
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
isExpiredTokenError(error: any): boolean {
|
||||
return error.errorcode === 'invalidtoken' ||
|
||||
(error.errorcode === 'accessexception' && error.message.includes('Invalid token - token expired'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue