Better error handling on nonexistent user
alex wennerberg alex@alexwennerberg.com
Thu, 14 Jan 2021 20:41:54 -0800
1 files changed,
10 insertions(+),
1 deletions(-)
jump to
M
http.go
→
http.go
@@ -379,7 +379,16 @@ var active bool
var isAdmin bool err := row.Scan(&username, &db_password, &active, &isAdmin) if err != nil { - panic(err) + if strings.Contains(err.Error(), "no rows") { + data := struct { + Error string + Config Config + }{"Username or email '" + name + "' does not exist", c} + t.ExecuteTemplate(w, "login.html", data) + return + } else { + panic(err) + } } if db_password != nil && !active { data := struct {