- fix: nModified è stato sostituito con modifiedCount

- .ok con .acknowledged
- coretto la chiamata per il REFRESH TOKEN !
This commit is contained in:
Surya Paolo
2025-03-14 10:55:30 +01:00
parent 0f8721b144
commit d190d4800e
13 changed files with 47 additions and 30 deletions

View File

@@ -121,7 +121,7 @@ export const Api = {
}
},
async checkTokenScaduto(status, evitaloop, resolve, reject, url, method, mydata, setAuthToken = false) {
async checkTokenScaduto(status, evitaloop, url, method, mydata, setAuthToken = false) {
const userStore = useUserStore();
if (status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_TOKEN_EXPIRED) {
@@ -134,12 +134,12 @@ export const Api = {
if (!evitaloop) {
console.log('Nuovo token ottenuto. Riprovo la richiesta...');
return resolve(this.SendReq(url, method, mydata, setAuthToken, true));
return await this.SendReq(url, method, mydata, setAuthToken, true);
}
} else {
// Se il refresh token fallisce, logout dell'utente
userStore.setAuth('', '');
return reject({ code: toolsext.ERR_AUTHENTICATION });
throw { code: toolsext.ERR_AUTHENTICATION };
}
} catch (err2) {
console.error('Errore durante il refresh token:', err2);
@@ -147,11 +147,11 @@ export const Api = {
if (err2?.code === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
userStore.setServerCode(toolsext.ERR_AUTHENTICATION);
userStore.setAuth('', '');
return reject({ code: toolsext.ERR_AUTHENTICATION });
throw { code: toolsext.ERR_AUTHENTICATION };
}
// Gestione di altri errori critici
return reject(err2);
throw err2;
}
}
@@ -190,8 +190,8 @@ export const Api = {
throw { code: toolsext.ERR_AUTHENTICATION };
}
// Verifica sul token (funzione custom, che deve restituire un valore se serve un nuovo flusso)
const ret = await this.checkTokenScaduto(res.status, evitaloop, res, null, url, method, mydata, setAuthToken);
// Verifica sul token (funzione custom)
const ret = await this.checkTokenScaduto(res.status, evitaloop, url, method, mydata, setAuthToken);
if (ret) return ret;
if (tools.isDebug()) console.log(' ----> ', res);
@@ -206,8 +206,9 @@ export const Api = {
}
}, 1000);
const ret = await this.checkTokenScaduto(error.status, evitaloop, null, error, url, method, mydataout, setAuthToken);
const ret = await this.checkTokenScaduto(error.status, evitaloop, url, method, mydataout, setAuthToken);
if (ret) return ret;
console.error('Errore nella richiesta:', error);
throw error;
}