|
@@ -8,7 +8,11 @@ export const request = axios.create({
|
|
|
timeout: 10000
|
|
|
});
|
|
|
|
|
|
-export const setupInterceptors = ({ showError }: { showError: (message: string) => void }) => {
|
|
|
+export const setupInterceptors = ({
|
|
|
+ showError
|
|
|
+}: {
|
|
|
+ showError: (message: string, loginNeeded: boolean) => void;
|
|
|
+}) => {
|
|
|
request.interceptors.request.use(
|
|
|
(config) => {
|
|
|
config.headers['App-Version'] = APP_VERSION;
|
|
@@ -23,9 +27,17 @@ export const setupInterceptors = ({ showError }: { showError: (message: string)
|
|
|
request.interceptors.response.use(
|
|
|
(response) => {
|
|
|
if (response.data.result === 'ERROR' && response.data.result_description) {
|
|
|
- setTimeout(() => {
|
|
|
- showError(response.data.result_description);
|
|
|
- }, 1000);
|
|
|
+ const showErrorWithDelay = (message: string, requiresLogin: boolean) => {
|
|
|
+ setTimeout(() => {
|
|
|
+ showError(message, requiresLogin);
|
|
|
+ }, 1000);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (response.data?.login_needed && response.data.login_needed === 1) {
|
|
|
+ showErrorWithDelay(response.data.result_description, true);
|
|
|
+ return response;
|
|
|
+ }
|
|
|
+ showErrorWithDelay(response.data.result_description, false);
|
|
|
}
|
|
|
return response;
|
|
|
},
|
|
@@ -33,13 +45,13 @@ export const setupInterceptors = ({ showError }: { showError: (message: string)
|
|
|
if (error.code === 'ECONNABORTED') {
|
|
|
error.isTimeout = true;
|
|
|
showBanner('Slow internet connection!');
|
|
|
-
|
|
|
+
|
|
|
return;
|
|
|
} else if (error.message === 'Network Error') {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- showError(error.message);
|
|
|
+ showError(error.message, false);
|
|
|
|
|
|
return Promise.reject(error);
|
|
|
}
|