http response name convention.

This commit is contained in:
Miroslav Šedivý 2020-11-28 15:00:21 +01:00
parent 3f312c84ad
commit c4978ba376
6 changed files with 11 additions and 11 deletions

View File

@ -30,7 +30,7 @@ func (h *MembersHandler) membersCreate(w http.ResponseWriter, r *http.Request) {
id, err := utils.NewUID(32) id, err := utils.NewUID(32)
if err != nil { if err != nil {
utils.HttpInternalServer(w, err) utils.HttpInternalServerError(w, err)
return return
} }
@ -74,7 +74,7 @@ func (h *MembersHandler) membersDelete(w http.ResponseWriter, r *http.Request) {
member := GetMember(r) member := GetMember(r)
if err := h.sessions.Delete(member.ID()); err != nil { if err := h.sessions.Delete(member.ID()); err != nil {
utils.HttpInternalServer(w, err) utils.HttpInternalServerError(w, err)
return return
} }

View File

@ -37,7 +37,7 @@ func (h *RoomHandler) boradcastStart(w http.ResponseWriter, r *http.Request) {
} }
if err := h.capture.StartBroadcast(data.URL); err != nil { if err := h.capture.StartBroadcast(data.URL); err != nil {
utils.HttpInternalServer(w, err) utils.HttpInternalServerError(w, err)
return return
} }

View File

@ -19,7 +19,7 @@ func (h *RoomHandler) screenConfiguration(w http.ResponseWriter, r *http.Request
size := h.desktop.GetScreenSize() size := h.desktop.GetScreenSize()
if size == nil { if size == nil {
utils.HttpInternalServer(w, "Unable to get screen configuration.") utils.HttpInternalServerError(w, "Unable to get screen configuration.")
return return
} }

View File

@ -52,7 +52,7 @@ func (api *ApiManagerCtx) Authenticate(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session, err := api.sessions.Authenticate(r) session, err := api.sessions.Authenticate(r)
if err != nil { if err != nil {
utils.HttpNotAuthenticated(w, err) utils.HttpUnauthorized(w, err)
} else { } else {
next.ServeHTTP(w, auth.SetSession(r, session)) next.ServeHTTP(w, auth.SetSession(r, session))
} }

View File

@ -27,7 +27,7 @@ func AdminsOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r) session := GetSession(r)
if !session.Admin() { if !session.Admin() {
utils.HttpNotAuthorized(w) utils.HttpForbidden(w)
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }
@ -38,7 +38,7 @@ func HostsOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r) session := GetSession(r)
if !session.IsHost() { if !session.IsHost() {
utils.HttpNotAuthorized(w, "Only host can do this.") utils.HttpForbidden(w, "Only host can do this.")
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }
@ -49,7 +49,7 @@ func HostsOrAdminsOnly(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
session := GetSession(r) session := GetSession(r)
if !session.IsHost() && !session.Admin() { if !session.IsHost() && !session.Admin() {
utils.HttpNotAuthorized(w, "Only host can do this.") utils.HttpForbidden(w, "Only host can do this.")
} else { } else {
next.ServeHTTP(w, r) next.ServeHTTP(w, r)
} }

View File

@ -50,11 +50,11 @@ func HttpBadRequest(w http.ResponseWriter, res ...interface{}) {
defHttpError(w, http.StatusBadRequest, "Bad Request.", res...) defHttpError(w, http.StatusBadRequest, "Bad Request.", res...)
} }
func HttpNotAuthorized(w http.ResponseWriter, res ...interface{}) { func HttpUnauthorized(w http.ResponseWriter, res ...interface{}) {
defHttpError(w, http.StatusUnauthorized, "Access token does not have the required scope.", res...) defHttpError(w, http.StatusUnauthorized, "Access token does not have the required scope.", res...)
} }
func HttpNotAuthenticated(w http.ResponseWriter, res ...interface{}) { func HttpForbidden(w http.ResponseWriter, res ...interface{}) {
defHttpError(w, http.StatusForbidden, "Invalid or missing access token.", res...) defHttpError(w, http.StatusForbidden, "Invalid or missing access token.", res...)
} }
@ -66,7 +66,7 @@ func HttpUnprocessableEntity(w http.ResponseWriter, res ...interface{}) {
defHttpError(w, http.StatusUnprocessableEntity, "Unprocessable Entity.", res...) defHttpError(w, http.StatusUnprocessableEntity, "Unprocessable Entity.", res...)
} }
func HttpInternalServer(w http.ResponseWriter, res ...interface{}) { func HttpInternalServerError(w http.ResponseWriter, res ...interface{}) {
defHttpError(w, http.StatusInternalServerError, "Internal server error.", res...) defHttpError(w, http.StatusInternalServerError, "Internal server error.", res...)
} }