From 4e6a78fb545531e864f34b4bd128d1fe9645fd78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miroslav=20=C5=A0ediv=C3=BD?= Date: Fri, 30 Oct 2020 22:39:35 +0100 Subject: [PATCH] update errors. --- internal/api/room/screen.go | 8 ++++---- internal/api/utils/error.go | 13 +++++++++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/internal/api/room/screen.go b/internal/api/room/screen.go index 64289fa5..30932939 100644 --- a/internal/api/room/screen.go +++ b/internal/api/room/screen.go @@ -31,7 +31,7 @@ func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request size := h.remote.GetScreenSize() 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 } @@ -45,17 +45,17 @@ func (h *RoomHandler) ScreenConfiguration(w http.ResponseWriter, r *http.Request func (h *RoomHandler) ScreenConfigurationChange(w http.ResponseWriter, r *http.Request) { data := &ScreenConfiguration{} if err := render.Bind(r, data); err != nil { - render.Render(w, r, utils.ErrInvalidRequest(err)) + render.Render(w, r, utils.ErrBadRequest(err)) return } 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 } 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 } diff --git a/internal/api/utils/error.go b/internal/api/utils/error.go index 8b0ed52e..05ee8ed3 100644 --- a/internal/api/utils/error.go +++ b/internal/api/utils/error.go @@ -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{ Err: err, 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(), } }