From f0628c1e14a4567e0d20696fd1d7f89d5400262c Mon Sep 17 00:00:00 2001 From: Stefan Majer Date: Wed, 14 Aug 2024 08:27:01 +0200 Subject: [PATCH] Satisfy new govet errors (#561) --- .../internal/service/machine-service_allocation_test.go | 5 +++-- cmd/metal-api/main.go | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/cmd/metal-api/internal/service/machine-service_allocation_test.go b/cmd/metal-api/internal/service/machine-service_allocation_test.go index 95c220ea..ffde006e 100644 --- a/cmd/metal-api/internal/service/machine-service_allocation_test.go +++ b/cmd/metal-api/internal/service/machine-service_allocation_test.go @@ -7,6 +7,7 @@ import ( "bytes" "context" "encoding/json" + "errors" "fmt" "log/slog" "net" @@ -226,7 +227,7 @@ func allocMachine(container *restful.Container, ar v1.MachineAllocateRequest) (v resp := w.Result() defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return v1.MachineResponse{}, fmt.Errorf(w.Body.String()) + return v1.MachineResponse{}, errors.New(w.Body.String()) } var result v1.MachineResponse err = json.NewDecoder(resp.Body).Decode(&result) @@ -248,7 +249,7 @@ func freeMachine(container *restful.Container, id string) (v1.MachineResponse, e resp := w.Result() defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return v1.MachineResponse{}, fmt.Errorf(w.Body.String()) + return v1.MachineResponse{}, errors.New(w.Body.String()) } var result v1.MachineResponse err = json.NewDecoder(resp.Body).Decode(&result) diff --git a/cmd/metal-api/main.go b/cmd/metal-api/main.go index d9369b79..31514a80 100644 --- a/cmd/metal-api/main.go +++ b/cmd/metal-api/main.go @@ -957,7 +957,7 @@ func run() error { restful.DefaultContainer.ServiceErrorHandler(func(serviceErr restful.ServiceError, request *restful.Request, response *restful.Response) { response.Header().Set("Content-Type", "application/json") response.WriteHeader(serviceErr.Code) - err := response.WriteAsJson(httperrors.NewHTTPError(serviceErr.Code, fmt.Errorf(serviceErr.Message))) + err := response.WriteAsJson(httperrors.NewHTTPError(serviceErr.Code, errors.New(serviceErr.Message))) if err != nil { logger.Error("Failed to send response", "error", err) return