Enha: avoid nil panics
This commit is contained in:
@ -72,8 +72,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
// get username
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
if err != nil || fi == nil {
|
||||
log.Error("failed to fetch fi", "error", err)
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
if fi.Room == nil {
|
||||
@ -111,8 +112,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) {
|
||||
func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
|
||||
// get username
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
if err != nil || fi == nil {
|
||||
log.Error("failed to fetch fi", "error", err)
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
// check if one who pressed it is from the team who has the turn
|
||||
@ -143,8 +145,9 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func HandleStartGame(w http.ResponseWriter, r *http.Request) {
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
if err != nil || fi == nil {
|
||||
log.Error("failed to fetch fi", "error", err)
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
// check if enough players
|
||||
@ -293,8 +296,9 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) {
|
||||
clue := r.PostFormValue("clue")
|
||||
num := r.PostFormValue("number")
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
if err != nil || fi == nil {
|
||||
log.Error("failed to fetch fi", "error", err)
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
guessLimitU64, err := strconv.ParseUint(num, 10, 8)
|
||||
@ -360,8 +364,9 @@ func HandleGiveClue(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
func HandleRenotifyBot(w http.ResponseWriter, r *http.Request) {
|
||||
fi, err := getFullInfoByCtx(r.Context())
|
||||
if err != nil {
|
||||
abortWithError(w, err.Error())
|
||||
if err != nil || fi == nil {
|
||||
log.Error("failed to fetch fi", "error", err)
|
||||
http.Redirect(w, r, "/", 302)
|
||||
return
|
||||
}
|
||||
notifyBotIfNeeded(fi.Room)
|
||||
|
Reference in New Issue
Block a user