2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-17 04:25:42 +00:00

make calls more robust

This commit is contained in:
Matthias Mair
2025-01-08 00:10:28 +01:00
parent e19c2e1c62
commit 18fdfc9b22
2 changed files with 9 additions and 5 deletions

View File

@ -316,13 +316,13 @@ export function authApi(
method: 'get' | 'post' | 'put' | 'delete' = 'get', method: 'get' | 'post' | 'put' | 'delete' = 'get',
data?: any data?: any
) { ) {
const [session] = useUserState((state) => [state.session]); const state = useUserState.getState();
// extend default axios instance with session token // extend default axios instance with session token
const requestConfig = config || {}; const requestConfig = config || {};
if (!requestConfig.headers) { if (!requestConfig.headers) {
requestConfig.headers = {}; requestConfig.headers = {};
} }
requestConfig.headers['X-Session-Token'] = session; requestConfig.headers['X-Session-Token'] = state.session;
// set method // set method
requestConfig.method = method; requestConfig.method = method;
@ -333,5 +333,5 @@ export function authApi(
} }
// use normal api // use normal api
return api.post(url, requestConfig); return api(url, requestConfig);
} }

View File

@ -20,8 +20,12 @@ export default function MainView() {
const [allowMobile] = useLocalState((state) => [state.allowMobile]); const [allowMobile] = useLocalState((state) => [state.allowMobile]);
// Set initial login status // Set initial login status
useEffect(() => { useEffect(() => {
// Local state initialization try {
setApiDefaults(); // Local state initialization
setApiDefaults();
} catch (e) {
console.error(e);
}
}, []); }, []);
// Check if mobile // Check if mobile