From 9c9e077bf980286b46ca697e1bdf7ac834d7bac9 Mon Sep 17 00:00:00 2001 From: Geraint Edwards Date: Fri, 10 Dec 2021 07:47:00 +0000 Subject: [PATCH] wrap the (server) error --- api/versions.go | 2 +- api/versions_test.go | 18 ++++++------------ 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/api/versions.go b/api/versions.go index 879cdd4c..b2b8c432 100644 --- a/api/versions.go +++ b/api/versions.go @@ -672,7 +672,7 @@ func handleVersionAPIErr(ctx context.Context, err error, w http.ResponseWriter, case strings.HasPrefix(err.Error(), "invalid version requested"): status = http.StatusBadRequest default: - err = fmt.Errorf("%s: %s", errs.ErrInternalServer.Error(), err.Error()) + err = fmt.Errorf("%s: %w", errs.ErrInternalServer.Error(), err) status = http.StatusInternalServerError } diff --git a/api/versions_test.go b/api/versions_test.go index 399ce7a7..2c1a40a4 100644 --- a/api/versions_test.go +++ b/api/versions_test.go @@ -1402,8 +1402,7 @@ func TestPutVersionReturnsError(t *testing.T) { api := GetAPIWithCMDMocks(mockedDataStore, generatorMock, datasetPermissions, permissions) api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0) @@ -2295,8 +2294,7 @@ func TestDetachVersionReturnsError(t *testing.T) { api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0) @@ -2362,8 +2360,7 @@ func TestDetachVersionReturnsError(t *testing.T) { api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0) @@ -2400,8 +2397,7 @@ func TestDetachVersionReturnsError(t *testing.T) { api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0) @@ -2484,8 +2480,7 @@ func TestDetachVersionReturnsError(t *testing.T) { api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0) @@ -2534,8 +2529,7 @@ func TestDetachVersionReturnsError(t *testing.T) { api.Router.ServeHTTP(w, r) - So(w.Code, ShouldEqual, http.StatusInternalServerError) - So(w.Body.String(), ShouldContainSubstring, errs.ErrInternalServer.Error()) + assertInternalServerErr(w) So(datasetPermissions.Required.Calls, ShouldEqual, 1) So(permissions.Required.Calls, ShouldEqual, 0)