token-validator: Try to have better error msg
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
52b218f2ea
commit
6dd9097351
2 changed files with 13 additions and 4 deletions
|
@ -59,14 +59,17 @@ func rawHandler(f func(http.ResponseWriter, *http.Request, httprouter.Params, []
|
|||
var student *adlin.Student = nil
|
||||
if cookie, err := r.Cookie("auth"); err == nil {
|
||||
if sessionid, err := base64.StdEncoding.DecodeString(cookie.Value); err != nil {
|
||||
http.SetCookie(w, &http.Cookie{Name: "auth", Value: "", Path: baseURL + "/", Expires: time.Time{}, HttpOnly: true})
|
||||
http.Error(w, fmt.Sprintf(`{"errmsg": %q}`, err), http.StatusNotAcceptable)
|
||||
return
|
||||
} else if session, err := adlin.GetSession(sessionid); err != nil {
|
||||
http.SetCookie(w, &http.Cookie{Name: "auth", Value: "", Path: baseURL + "/", Expires: time.Time{}, HttpOnly: true})
|
||||
http.Error(w, fmt.Sprintf(`{"errmsg": %q}`, err), http.StatusUnauthorized)
|
||||
return
|
||||
} else if session.IdStudent == nil {
|
||||
student = nil
|
||||
} else if std, err := adlin.GetStudent(int(*session.IdStudent)); err != nil {
|
||||
http.SetCookie(w, &http.Cookie{Name: "auth", Value: "", Path: baseURL + "/", Expires: time.Time{}, HttpOnly: true})
|
||||
http.Error(w, fmt.Sprintf(`{"errmsg": %q}`, err), http.StatusUnauthorized)
|
||||
return
|
||||
} else {
|
||||
|
|
Reference in a new issue