diff --git a/backend/app/api/handlers/v1/v1_ctrl_auth.go b/backend/app/api/handlers/v1/v1_ctrl_auth.go index a3f49b4..4b3c0a4 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_auth.go +++ b/backend/app/api/handlers/v1/v1_ctrl_auth.go @@ -42,8 +42,6 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { err := r.ParseForm() if err != nil { return server.Respond(w, http.StatusBadRequest, server.Wrap(err)) - log.Error().Err(err).Msg("failed to parse form") - return nil } loginForm.Username = r.PostFormValue("username") @@ -53,12 +51,9 @@ func (ctrl *V1Controller) HandleAuthLogin() server.HandlerFunc { if err != nil { log.Err(err).Msg("failed to decode login form") - return server.Respond(w, http.StatusBadRequest, server.Wrap(err)) - return nil } default: return server.Respond(w, http.StatusBadRequest, errors.New("invalid content type")) - return nil } if loginForm.Username == "" || loginForm.Password == "" { diff --git a/backend/app/api/handlers/v1/v1_ctrl_items.go b/backend/app/api/handlers/v1/v1_ctrl_items.go index 09cbb5b..367db26 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items.go @@ -139,6 +139,7 @@ func (ctrl *V1Controller) handleItemsGeneral() server.HandlerFunc { ctx := services.NewContext(r.Context()) ID, err := ctrl.routeID(w, r) if err != nil { + return err } switch r.Method { diff --git a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go index 436761d..00421a2 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go +++ b/backend/app/api/handlers/v1/v1_ctrl_items_attachments.go @@ -73,6 +73,7 @@ func (ctrl *V1Controller) HandleItemAttachmentCreate() server.HandlerFunc { id, err := ctrl.routeID(w, r) if err != nil { + return err } ctx := services.NewContext(r.Context()) @@ -162,6 +163,7 @@ func (ctrl *V1Controller) HandleItemAttachmentUpdate() server.HandlerFunc { func (ctrl *V1Controller) handleItemAttachmentsHandler(w http.ResponseWriter, r *http.Request) error { ID, err := ctrl.routeID(w, r) if err != nil { + return err } attachmentId, err := uuid.Parse(chi.URLParam(r, "attachment_id")) diff --git a/backend/app/api/handlers/v1/v1_ctrl_labels.go b/backend/app/api/handlers/v1/v1_ctrl_labels.go index c1a05d9..d9863fb 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_labels.go +++ b/backend/app/api/handlers/v1/v1_ctrl_labels.go @@ -98,6 +98,7 @@ func (ctrl *V1Controller) handleLabelsGeneral() server.HandlerFunc { ctx := services.NewContext(r.Context()) ID, err := ctrl.routeID(w, r) if err != nil { + return err } switch r.Method { diff --git a/backend/app/api/handlers/v1/v1_ctrl_locations.go b/backend/app/api/handlers/v1/v1_ctrl_locations.go index 6b7bed7..833467b 100644 --- a/backend/app/api/handlers/v1/v1_ctrl_locations.go +++ b/backend/app/api/handlers/v1/v1_ctrl_locations.go @@ -100,6 +100,7 @@ func (ctrl *V1Controller) handleLocationGeneral() server.HandlerFunc { ctx := services.NewContext(r.Context()) ID, err := ctrl.routeID(w, r) if err != nil { + return err } switch r.Method { diff --git a/backend/app/api/routes.go b/backend/app/api/routes.go index 4813e43..02a7f74 100644 --- a/backend/app/api/routes.go +++ b/backend/app/api/routes.go @@ -10,7 +10,6 @@ import ( "path" "path/filepath" - "github.com/go-chi/chi/v5" "github.com/hay-kot/homebox/backend/app/api/handlers/debughandlers" v1 "github.com/hay-kot/homebox/backend/app/api/handlers/v1" _ "github.com/hay-kot/homebox/backend/app/api/static/docs" @@ -108,27 +107,6 @@ func (a *app) mountRoutes(repos *repo.AllRepos) { a.server.NotFound(notFoundHandler()) } -// logRoutes logs the routes of the server that are registered within Server.registerRoutes(). This is useful for debugging. -// See https://github.com/go-chi/chi/issues/332 for details and inspiration. -func (a *app) logRoutes(r *chi.Mux) { - desiredSpaces := 10 - - walkFunc := func(method string, route string, handler http.Handler, middleware ...func(http.Handler) http.Handler) error { - text := "[" + method + "]" - - for len(text) < desiredSpaces { - text = text + " " - } - - fmt.Printf("Registered Route: %s%s\n", text, route) - return nil - } - - if err := chi.Walk(r, walkFunc); err != nil { - fmt.Printf("Logging err: %s\n", err.Error()) - } -} - func registerMimes() { err := mime.AddExtensionType(".js", "application/javascript") if err != nil { diff --git a/backend/pkgs/server/mux.go b/backend/pkgs/server/mux.go index b8c607d..9e77e32 100644 --- a/backend/pkgs/server/mux.go +++ b/backend/pkgs/server/mux.go @@ -43,7 +43,7 @@ func (s *Server) toHttpHandler(handler Handler, mw ...Middleware) http.HandlerFu if err != nil { if IsShutdownError(err) { - s.Shutdown("SIGTERM") + _ = s.Shutdown("SIGTERM") } } } diff --git a/backend/pkgs/server/response_error_builder.go b/backend/pkgs/server/response_error_builder.go index 4c6d80f..cc573e2 100644 --- a/backend/pkgs/server/response_error_builder.go +++ b/backend/pkgs/server/response_error_builder.go @@ -72,5 +72,5 @@ func (eb *ErrorBuilder) AddError(err error) { // Respond sends a JSON response with the ErrorBuilder's errors. If there are no errors, then // the errors field will be an empty array. func (eb *ErrorBuilder) Respond(w http.ResponseWriter, statusCode int) { - Respond(w, statusCode, Wrap(nil).AddError(http.StatusText(statusCode), eb.errs)) + _ = Respond(w, statusCode, Wrap(nil).AddError(http.StatusText(statusCode), eb.errs)) } diff --git a/backend/pkgs/server/response_test.go b/backend/pkgs/server/response_test.go index a438715..ef23d60 100644 --- a/backend/pkgs/server/response_test.go +++ b/backend/pkgs/server/response_test.go @@ -16,7 +16,8 @@ func Test_Respond_NoContent(t *testing.T) { Name: "dummy", } - Respond(recorder, http.StatusNoContent, dummystruct) + err := Respond(recorder, http.StatusNoContent, dummystruct) + assert.NoError(t, err) assert.Equal(t, http.StatusNoContent, recorder.Code) assert.Empty(t, recorder.Body.String()) @@ -30,7 +31,8 @@ func Test_Respond_JSON(t *testing.T) { Name: "dummy", } - Respond(recorder, http.StatusCreated, dummystruct) + err := Respond(recorder, http.StatusCreated, dummystruct) + assert.NoError(t, err) assert.Equal(t, http.StatusCreated, recorder.Code) assert.JSONEq(t, recorder.Body.String(), `{"name":"dummy"}`)