-
Notifications
You must be signed in to change notification settings - Fork 119
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
runservice: return right error on not existing run #451
Conversation
@alessandro-sorint Instead of doing a fix by just adding a missing return lets convert it to a style that avoid such errors using a new function instead of putting all the logic in ServeHTTP. See for example 1e5cb9e where we use a |
780ba5a
to
2effc50
Compare
@sgotti I added a do function |
} | ||
|
||
cgts, err := types.MarshalChangeGroupsUpdateToken(cgt) | ||
if err != nil { | ||
http.Error(w, err.Error(), http.StatusInternalServerError) | ||
return | ||
return nil, util.NewAPIError(util.ErrInternal, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As above.
@@ -540,22 +550,19 @@ func (h *RunByGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
}) | |||
if err != nil { | |||
h.log.Err(err).Send() | |||
http.Error(w, err.Error(), http.StatusInternalServerError) | |||
return | |||
return nil, util.NewAPIError(util.ErrInternal, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just return errors.WithStack(err). No need to explicitly define an ErrInternal. Every error not of type APIError is considered by http util an internal error. See the other APIs.
@@ -540,22 +550,19 @@ func (h *RunByGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | |||
}) | |||
if err != nil { | |||
h.log.Err(err).Send() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove logging.
tests/setup_test.go
Outdated
@@ -5780,6 +5780,39 @@ func TestGetProjectRuns(t *testing.T) { | |||
} | |||
}) | |||
} | |||
|
|||
t.Run("test get run not exists", func(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
test get not existing run
2effc50
to
753b471
Compare
A missing return after nil run check caused the return of a wrong error. Fix this by moving the logic to a dedicated function instead of doing everything in ServeHTTP.
753b471
to
ca84e0c
Compare
A missing return after nil run check caused the return of a wrong error.
Fix this by moving the logic to a dedicated function instead of doing everything in ServeHTTP.