Commit 981f7d0f authored by Miklós Tóth's avatar Miklós Tóth 🤷
Browse files

Improve join error msg handling

parent 1f6e3322
Pipeline #8844 passed with stages
in 1 minute and 19 seconds
......@@ -2,7 +2,7 @@ let joinAttempts = 0
function loginOrRegister(force){
if (joinAttempts > 5) {
throw "failed to join"
throw lastError || "failed to join"
}
joinAttempts++
......@@ -115,6 +115,7 @@ function handleResponse(action, response){
let intervalId;
let sock;
let lastError;
function createSocket() {
if (sock) {
......@@ -145,15 +146,16 @@ function createSocket() {
if (data.code < 300) {
handleResponse(data.cmd, data.msg);
} else {
if (data.code !== 200 && data.cmd === "join") {
// if registration was unsuccessful, don't stick with if after reload
try {
sock.send(JSON.stringify(loginOrRegister(true)));
} catch (e) {
alert(e)
if (data.code !== 200) {
lastError = data.msg;
if (data.cmd === "join") {
// if registration was unsuccessful, don't stick with if after reload
try {
sock.send(JSON.stringify(loginOrRegister(true)));
} catch (e) {
changeTeamName(e)
}
}
} else {
alert([data.code, data.msg]);
}
}
};
......
......@@ -97,7 +97,11 @@ func socketHandler(session sockjs.Session) {
func joinTeam(joinTeamId string, session sockjs.Session, teamId *string, userId string) {
name, e := db.GetTeam(session.Context(), joinTeamId)
weFdUp := e != redis.Nil
weFdUp := true
if e == redis.Nil {
weFdUp = false
e = errors.New("invalid team id")
}
if handleError(session, e, weFdUp, "join") {
return
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment