Skip to content

Commit

Permalink
Fix threads
Browse files Browse the repository at this point in the history
  • Loading branch information
tp47 committed Oct 8, 2023
1 parent 9e48315 commit c502b47
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 11 deletions.
6 changes: 3 additions & 3 deletions src/shared/api/HTTPClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<TResponse>(path: string, options: Options = {}): Promise<TResponse> {
Expand Down
4 changes: 3 additions & 1 deletion src/shared/api/WSClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,9 @@ class WSClient extends EventBus {
return;
}
this.dispatch(WSTransportEvents.Message, data);
} catch (error) {}
} catch (error) {
console.error(error);
}
});
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/shared/api/auth/auth.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<SignupResponse> {
Expand Down
4 changes: 1 addition & 3 deletions src/shared/api/chat/chat.api.ts
Original file line number Diff line number Diff line change
@@ -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<Chat[]> {
Expand Down
2 changes: 1 addition & 1 deletion src/shared/api/user/user.api.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
10 changes: 8 additions & 2 deletions src/widgets/auth/api/auth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down

0 comments on commit c502b47

Please sign in to comment.