refactor HTTP error.

This commit is contained in:
Miroslav Šedivý
2021-09-16 20:16:51 +02:00
parent d46c5d9d30
commit 4fa11e6a2a
15 changed files with 166 additions and 102 deletions

View File

@ -25,7 +25,7 @@ func AdminsOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.Profile().IsAdmin {
utils.HttpForbidden(w)
utils.HttpForbidden(w).Msg("session is not admin")
} else {
next.ServeHTTP(w, r)
}
@ -36,7 +36,7 @@ func HostsOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.IsHost() {
utils.HttpForbidden(w, "only host can do this")
utils.HttpForbidden(w).Msg("session is not host")
} else {
next.ServeHTTP(w, r)
}
@ -47,7 +47,7 @@ func CanWatchOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.Profile().CanWatch {
utils.HttpForbidden(w)
utils.HttpForbidden(w).Msg("session cannot watch")
} else {
next.ServeHTTP(w, r)
}
@ -58,7 +58,7 @@ func CanHostOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.Profile().CanHost {
utils.HttpForbidden(w)
utils.HttpForbidden(w).Msg("session cannot host")
} else {
next.ServeHTTP(w, r)
}
@ -69,7 +69,7 @@ func CanAccessClipboardOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r)
if !session.Profile().CanAccessClipboard {
utils.HttpForbidden(w)
utils.HttpForbidden(w).Msg("session cannot access clipboard")
} else {
next.ServeHTTP(w, r)
}