2
0
mirror of https://github.com/inventree/InvenTree.git synced 2025-06-16 20:15:44 +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',
data?: any
) {
const [session] = useUserState((state) => [state.session]);
const state = useUserState.getState();
// extend default axios instance with session token
const requestConfig = config || {};
if (!requestConfig.headers) {
requestConfig.headers = {};
}
requestConfig.headers['X-Session-Token'] = session;
requestConfig.headers['X-Session-Token'] = state.session;
// set method
requestConfig.method = method;
@ -333,5 +333,5 @@ export function authApi(
}
// 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]);
// Set initial login status
useEffect(() => {
// Local state initialization
setApiDefaults();
try {
// Local state initialization
setApiDefaults();
} catch (e) {
console.error(e);
}
}, []);
// Check if mobile