From d0f037200bc5e612ecc89559878d99336ea47871 Mon Sep 17 00:00:00 2001 From: Evgeny Talagaev Date: Wed, 18 Oct 2023 14:05:50 +0300 Subject: [PATCH] Fix autologin redirect --- src/controllers/AuthController.ts | 9 ++++++--- src/controllers/ChatsController.ts | 12 ++++++++---- src/controllers/UsersController.ts | 12 ++++++++---- src/utils/http.ts | 2 +- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/controllers/AuthController.ts b/src/controllers/AuthController.ts index 05ee37dad..a30eaf519 100644 --- a/src/controllers/AuthController.ts +++ b/src/controllers/AuthController.ts @@ -14,7 +14,8 @@ class AuthController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -31,14 +32,16 @@ class AuthController { return; } - if (res.response === 'User already in system') { + const { reason } = res.response; + + if (reason === 'User already in system') { sessionStorage.setItem("inSystem", "true"); router.go('/messenger'); return; } - Store.set('error', res.response); + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); diff --git a/src/controllers/ChatsController.ts b/src/controllers/ChatsController.ts index 00a9a97bd..24bed7679 100644 --- a/src/controllers/ChatsController.ts +++ b/src/controllers/ChatsController.ts @@ -20,7 +20,8 @@ class ChatsController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -36,7 +37,8 @@ class ChatsController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -61,7 +63,8 @@ class ChatsController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -129,7 +132,8 @@ class ChatsController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); diff --git a/src/controllers/UsersController.ts b/src/controllers/UsersController.ts index ea0cca4da..2ac79101a 100644 --- a/src/controllers/UsersController.ts +++ b/src/controllers/UsersController.ts @@ -17,7 +17,8 @@ class UsersController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -33,7 +34,8 @@ class UsersController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -47,7 +49,8 @@ class UsersController { return; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); }) .catch((error) => { console.error(`${error}`); @@ -61,7 +64,8 @@ class UsersController { return res.response; } - Store.set('error', res.response); + const { reason } = res.response; + Store.set('error', reason); } public async request(id: number) { diff --git a/src/utils/http.ts b/src/utils/http.ts index 2e2d14ce7..f5056e489 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -96,7 +96,7 @@ class HTTP implements IHTTP { try { response = JSON.parse(xhr.responseText); } catch (error) { - console.error(error); + // Send error to logger } const data = {