From c502b471822672d25847644cf45a60d256fe237d Mon Sep 17 00:00:00 2001 From: Ratmir Tsaregorodtsev Date: Sun, 8 Oct 2023 13:12:38 +0300 Subject: [PATCH] Fix threads --- src/shared/api/HTTPClient.ts | 6 +++--- src/shared/api/WSClient.ts | 4 +++- src/shared/api/auth/auth.api.ts | 2 +- src/shared/api/chat/chat.api.ts | 4 +--- src/shared/api/user/user.api.ts | 2 +- src/widgets/auth/api/auth.controller.ts | 10 ++++++++-- 6 files changed, 17 insertions(+), 11 deletions(-) diff --git a/src/shared/api/HTTPClient.ts b/src/shared/api/HTTPClient.ts index 4ca69a1f1..2ef80592b 100644 --- a/src/shared/api/HTTPClient.ts +++ b/src/shared/api/HTTPClient.ts @@ -29,10 +29,10 @@ function setHeaders(xhr: XMLHttpRequest, headers: object) { } class HTTPClient { - private base: string = ""; + private base: string = "https://ya-praktikum.tech/api/v2"; - constructor(base: string) { - this.base = base; + constructor(endpoint: string) { + this.base.concat(endpoint); } get(path: string, options: Options = {}): Promise { diff --git a/src/shared/api/WSClient.ts b/src/shared/api/WSClient.ts index 67693dcc5..4640f576c 100644 --- a/src/shared/api/WSClient.ts +++ b/src/shared/api/WSClient.ts @@ -82,7 +82,9 @@ class WSClient extends EventBus { return; } this.dispatch(WSTransportEvents.Message, data); - } catch (error) {} + } catch (error) { + console.error(error); + } }); } } diff --git a/src/shared/api/auth/auth.api.ts b/src/shared/api/auth/auth.api.ts index 14fcb4e34..62d20c35d 100644 --- a/src/shared/api/auth/auth.api.ts +++ b/src/shared/api/auth/auth.api.ts @@ -2,7 +2,7 @@ import { APIError, HTTPClient } from "@/shared/api"; import { User } from "@/shared/api/user"; import { LoginRequest, SignupRequest, SignupResponse } from "./auth.types"; -const authAPIInstance = new HTTPClient("https://ya-praktikum.tech/api/v2/auth"); +const authAPIInstance = new HTTPClient("/auth"); class AuthAPI { public async signup(data: SignupRequest): Promise { diff --git a/src/shared/api/chat/chat.api.ts b/src/shared/api/chat/chat.api.ts index b4ba6471b..49238c8b1 100644 --- a/src/shared/api/chat/chat.api.ts +++ b/src/shared/api/chat/chat.api.ts @@ -1,9 +1,7 @@ import { ChatWebsocket, HTTPClient } from "@/shared/api"; import { Chat } from "./chat.types"; -const chatAPIInstance = new HTTPClient( - "https://ya-praktikum.tech/api/v2/chats", -); +const chatAPIInstance = new HTTPClient("/chats"); class ChatAPI { public async getAll(): Promise { diff --git a/src/shared/api/user/user.api.ts b/src/shared/api/user/user.api.ts index ad49fa0f1..eb1b41462 100644 --- a/src/shared/api/user/user.api.ts +++ b/src/shared/api/user/user.api.ts @@ -1,6 +1,6 @@ import { HTTPClient } from "@/shared/api"; -const userAPIInstance = new HTTPClient("https://ya-praktikum.tech/api/v2/user"); +const userAPIInstance = new HTTPClient("/user"); class UserAPI { public async editUser(data: any) { diff --git a/src/widgets/auth/api/auth.controller.ts b/src/widgets/auth/api/auth.controller.ts index fc481befe..308b7521d 100644 --- a/src/widgets/auth/api/auth.controller.ts +++ b/src/widgets/auth/api/auth.controller.ts @@ -11,7 +11,11 @@ class AuthController { window.router.go(Routes.Messenger); const user = await authApi.getUser(); window.store.set({ user }); - } catch (error) {} + } catch (error) { + const user = await authApi.getUser(); + window.store.set({ user }); + window.router.go(Routes.Messenger); + } } public async signup(data: SignupFormModel) { @@ -22,7 +26,9 @@ class AuthController { const user = await authApi.getUser(); window.store.set({ user }); } - } catch (error) {} + } catch (error) { + console.error(error); + } } public async logout() {