- risolto problema della non attesa della PWA durante la chiamata a Node.js.
- risolto problema dell'ambiente in Locale HTTPS certificato installato aggiornato.
This commit is contained in:
@@ -41,43 +41,43 @@ export const Api = {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.downloading_server = 1
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('post', path, payload, responsedata, options)
|
||||
return await Request('post', path, payload, responsedata, options)
|
||||
},
|
||||
|
||||
async postFormData(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
globalStore.connData.downloading_server = 1
|
||||
return Request('postFormData', path, payload, responsedata)
|
||||
return await Request('postFormData', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async get(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.downloading_server = 1
|
||||
globalStore.connData.uploading_server = 0
|
||||
return Request('get', path, payload, responsedata)
|
||||
return await Request('get', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async put(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('put', path, payload, responsedata)
|
||||
return await Request('put', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async patch(path: string, payload?: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('patch', path, payload, responsedata)
|
||||
return await Request('patch', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async Delete(path: string, payload: any, responsedata?: any) {
|
||||
const globalStore = useGlobalStore()
|
||||
globalStore.connData.uploading_server = 1
|
||||
return Request('delete', path, payload, responsedata)
|
||||
return await Request('delete', path, payload, responsedata)
|
||||
},
|
||||
|
||||
async checkSession({ token, refresh_token }: any) {
|
||||
return axios.post(import.meta.env.VITE_API_URL + Paths.TOKEN_REFRESH, {
|
||||
return await axios.post(import.meta.env.VITE_API_URL + Paths.TOKEN_REFRESH, {
|
||||
refresh_token,
|
||||
}, {
|
||||
headers: {
|
||||
@@ -158,70 +158,61 @@ export const Api = {
|
||||
return null;
|
||||
},
|
||||
|
||||
async SendReqBase(url: string, method: string, mydata: any, setAuthToken = false, evitaloop = false, myformdata?: any, responsedata?: any, options?: any): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
// Base per la chiamata con gestione degli errori e retry
|
||||
async SendReqBase(url, method, mydata, setAuthToken = false, evitaloop = false, myformdata, responsedata, options) {
|
||||
const mydataout = {
|
||||
...mydata,
|
||||
keyappid: import.meta.env.VITE_PAO_APP_ID,
|
||||
idapp: tools.getEnv('VITE_APP_ID'),
|
||||
}
|
||||
};
|
||||
|
||||
const userStore = useUserStore()
|
||||
const globalStore = useGlobalStore()
|
||||
const userStore = useUserStore();
|
||||
const globalStore = useGlobalStore();
|
||||
userStore.setServerCode(tools.EMPTY);
|
||||
userStore.setResStatus(0);
|
||||
|
||||
try {
|
||||
const res = await sendRequest(url, method, mydataout, myformdata, responsedata, options);
|
||||
|
||||
userStore.setServerCode(tools.EMPTY)
|
||||
userStore.setResStatus(0)
|
||||
|
||||
return new Promise((resolve, reject) => sendRequest(url, method, mydataout, myformdata, responsedata, options)
|
||||
.then(async (res) => {
|
||||
setTimeout(() => {
|
||||
if (method === 'get') {
|
||||
globalStore.connData.downloading_server = 0
|
||||
} else {
|
||||
globalStore.connData.uploading_server = 0
|
||||
globalStore.connData.downloading_server = 0
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
userStore.setServerCode(toolsext.ERR_AUTHENTICATION);
|
||||
userStore.setAuth('', '');
|
||||
return reject({ code: toolsext.ERR_AUTHENTICATION });
|
||||
}
|
||||
|
||||
const ret = await this.checkTokenScaduto(res.status, evitaloop, resolve, reject, url, method, mydata, setAuthToken);
|
||||
if (ret) {
|
||||
return ret;
|
||||
}
|
||||
|
||||
if (tools.isDebug())
|
||||
console.log(' ----> ', res)
|
||||
|
||||
return resolve(res)
|
||||
})
|
||||
.catch(async (error) => {
|
||||
setTimeout(() => {
|
||||
if (method === 'get') {
|
||||
globalStore.connData.downloading_server = -1
|
||||
} else {
|
||||
globalStore.connData.uploading_server = -1
|
||||
globalStore.connData.downloading_server = -1
|
||||
}
|
||||
}, 1000)
|
||||
|
||||
let ret = await this.checkTokenScaduto(error.status, evitaloop, resolve, reject, url, method, mydataout, setAuthToken)
|
||||
if (ret) {
|
||||
return ret
|
||||
// Aggiornamento dello stato della connessione dopo 1 secondo
|
||||
setTimeout(() => {
|
||||
if (method.toLowerCase() === 'get') {
|
||||
globalStore.connData.downloading_server = 0;
|
||||
} else {
|
||||
ret = await this.checkTokenScaduto(error.status, evitaloop, resolve, reject, url, method, mydataout, setAuthToken)
|
||||
globalStore.connData.uploading_server = 0;
|
||||
globalStore.connData.downloading_server = 0;
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
console.error('Errore nella richiesta:', error);
|
||||
return reject(error);
|
||||
}))
|
||||
if (res.status === serv_constants.RIS_CODE__HTTP_FORBIDDEN_INVALID_TOKEN) {
|
||||
userStore.setServerCode(toolsext.ERR_AUTHENTICATION);
|
||||
userStore.setAuth('', '');
|
||||
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);
|
||||
if (ret) return ret;
|
||||
|
||||
if (tools.isDebug()) console.log(' ----> ', res);
|
||||
return res;
|
||||
} catch (error) {
|
||||
setTimeout(() => {
|
||||
if (method.toLowerCase() === 'get') {
|
||||
globalStore.connData.downloading_server = -1;
|
||||
} else {
|
||||
globalStore.connData.uploading_server = -1;
|
||||
globalStore.connData.downloading_server = -1;
|
||||
}
|
||||
}, 1000);
|
||||
|
||||
const ret = await this.checkTokenScaduto(error.status, evitaloop, null, error, url, method, mydataout, setAuthToken);
|
||||
if (ret) return ret;
|
||||
console.error('Errore nella richiesta:', error);
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Promise that resolves after a specified number of milliseconds.
|
||||
* Useful for creating delayed operations or pause in async functions.
|
||||
@@ -254,43 +245,17 @@ export const Api = {
|
||||
return new Promise(resolve => setTimeout(resolve, ms));
|
||||
},
|
||||
|
||||
async SendReq(
|
||||
url: string,
|
||||
method: string,
|
||||
mydata: any,
|
||||
setAuthToken = false,
|
||||
evitaloop = false,
|
||||
retryCount = 3,
|
||||
retryDelay = 5000,
|
||||
myformdata?: any,
|
||||
responsedata?: any,
|
||||
options?: any,
|
||||
): Promise<Types.AxiosSuccess | Types.AxiosError> {
|
||||
// Funzione che gestisce la chiamata con retry
|
||||
async SendReq(url, method, mydata, setAuthToken = false, evitaloop = false, retryCount = 3, retryDelay = 5000, myformdata = null, responsedata = null, options = null) {
|
||||
try {
|
||||
const response = await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop, myformdata, responsedata, options);
|
||||
return response;
|
||||
} catch (error: any) {
|
||||
let riprova = true
|
||||
try {
|
||||
riprova = (error.status !== 403);
|
||||
} catch (e) {
|
||||
|
||||
}
|
||||
return await this.SendReqBase(url, method, mydata, setAuthToken, evitaloop, myformdata, responsedata, options);
|
||||
} catch (error) {
|
||||
// Se lo status non è 403 e sono rimasti tentativi, eseguo il retry
|
||||
const riprova = error.status !== 403;
|
||||
if (retryCount > 0 && riprova) {
|
||||
// (!error.hasOwnProperty('data') || (error.hasOwnProperty('data') && !error.data.error.hasOwnProperty('code')) && (!error.hasOwnProperty('msgerr')))
|
||||
console.log(`❌❌❌ Retrying request. Attempts remaining: ${retryCount}`);
|
||||
await this.delay(retryDelay);
|
||||
return this.SendReq(
|
||||
url,
|
||||
method,
|
||||
mydata,
|
||||
setAuthToken,
|
||||
evitaloop,
|
||||
retryCount - 1,
|
||||
retryDelay,
|
||||
myformdata,
|
||||
responsedata,
|
||||
);
|
||||
return this.SendReq(url, method, mydata, setAuthToken, evitaloop, retryCount - 1, retryDelay, myformdata, responsedata);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user