update errors.

This commit is contained in:
Miroslav Šedivý 2020-10-30 22:39:35 +01:00
parent c77d2b0305
commit 4e6a78fb54
2 changed files with 15 additions and 6 deletions

View File

@ -31,7 +31,7 @@ func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request
size := h.remote.GetScreenSize() size := h.remote.GetScreenSize()
if size == nil { if size == nil {
render.Render(w, r, utils.ErrMessage(500, "Not implmented.")) render.Render(w, r, utils.ErrMessage(500, "Unable to get screen configuration."))
return return
} }
@ -45,17 +45,17 @@ func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request
func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.Request) { func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.Request) {
data := &ScreenConfiguration{} data := &ScreenConfiguration{}
if err := render.Bind(r, data); err != nil { if err := render.Bind(r, data); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err)) render.Render(w, r, utils.ErrBadRequest(err))
return return
} }
if err := h.remote.ChangeResolution(data.Width, data.Height, data.Rate); err != nil { if err := h.remote.ChangeResolution(data.Width, data.Height, data.Rate); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err)) render.Render(w, r, utils.ErrUnprocessableEntity(err))
return return
} }
if err := broadcast.ScreenConfiguration(h.sessions, "-todo-session-id-", data.Width, data.Height, data.Rate); err != nil { if err := broadcast.ScreenConfiguration(h.sessions, "-todo-session-id-", data.Width, data.Height, data.Rate); err != nil {
render.Render(w, r, utils.ErrInvalidRequest(err)) render.Render(w, r, utils.ErrInternalServer(err))
return return
} }

View File

@ -36,11 +36,20 @@ func ErrMessage(HTTPStatusCode int, StatusText string) render.Renderer {
} }
} }
func ErrInvalidRequest(err error) render.Renderer { func ErrBadRequest(err error) render.Renderer {
return &ErrResponse{ return &ErrResponse{
Err: err, Err: err,
HTTPStatusCode: 400, HTTPStatusCode: 400,
StatusText: "Invalid request.", StatusText: "Bad request.",
ErrorText: err.Error(),
}
}
func ErrUnprocessableEntity(err error) render.Renderer {
return &ErrResponse{
Err: err,
HTTPStatusCode: 400,
StatusText: "Unprocessable Entity.",
ErrorText: err.Error(), ErrorText: err.Error(),
} }
} }