WS connection crash fix
- constructor() in index.js would attempt to fetch profile with getProfile() before websocket connection was established
This commit is contained in:
18
src/index.js
18
src/index.js
@@ -118,20 +118,22 @@ let Global = class {
|
|||||||
method: "GET",
|
method: "GET",
|
||||||
credentials: "include",
|
credentials: "include",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json"
|
"Accept": "application/json"
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if(res.status === 401) {
|
if(res.status === 401) {
|
||||||
return res.status
|
return res.status
|
||||||
}
|
}
|
||||||
if (!res.ok) throw new Error("Failed to fetch profile");
|
if (!res.ok) return res.status;
|
||||||
|
|
||||||
const profile = await res.json();
|
const profile = await res.json();
|
||||||
console.log("getProfile: ", profile);
|
console.log("getProfile: ", profile);
|
||||||
this.profile = profile
|
this.profile = profile
|
||||||
|
return 200;
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
return 401;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,16 +141,14 @@ let Global = class {
|
|||||||
window.addEventListener("navigate", this.onNavigate)
|
window.addEventListener("navigate", this.onNavigate)
|
||||||
|
|
||||||
this.getProfile().then(async (status) => {
|
this.getProfile().then(async (status) => {
|
||||||
|
if (status === 401) {
|
||||||
await this.Socket.init()
|
Login()
|
||||||
|
} else {
|
||||||
if(status !== 401) {
|
await this.Socket.init()
|
||||||
await this.onNavigate()
|
await this.onNavigate()
|
||||||
Home()
|
Home()
|
||||||
} else {
|
|
||||||
Login()
|
|
||||||
}
|
}
|
||||||
})
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user