Skip to content

Commit

Permalink
wrap the (server) error
Browse files Browse the repository at this point in the history
  • Loading branch information
gedge committed Dec 10, 2021
1 parent 34d1776 commit 9c9e077
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
2 changes: 1 addition & 1 deletion api/versions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
18 changes: 6 additions & 12 deletions api/versions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9c9e077

Please sign in to comment.