Skip to content
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

return code 409 instead of 500 for revert conflict #3538

Merged
merged 5 commits into from
Jun 23, 2022

Conversation

itaidavid
Copy link
Contributor

handleAPIError mapped graveler.ErrConflictFound to the default http.StatusInternalServerError (500) instead of the expected http.StatusConflict (409)
Fixed that and added an Esti test to create a conflict, attempt a revert and verify the status code

@itaidavid itaidavid added the include-changelog PR description should be included in next release changelog label Jun 22, 2022
@itaidavid itaidavid linked an issue Jun 22, 2022 that may be closed by this pull request
@itaidavid
Copy link
Contributor Author

Closes #3482

Copy link
Contributor

@itaiad200 itaiad200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New responses need to be added to the swagger file too.

@@ -1751,7 +1751,8 @@ func handleAPIError(w http.ResponseWriter, err error) bool {
errors.Is(err, actions.ErrParamConflict):
writeError(w, http.StatusBadRequest, err)

case errors.Is(err, graveler.ErrNotUnique):
case errors.Is(err, graveler.ErrNotUnique),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder why there's 2 conflict like graveler errors.. Just making sure we don't override some other flow error handling that returned graveler.ErrConflictFound

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is a good question. Actually, the controller handles graveler.ErrConflictFound specifically for Merge and returns http.StatusConflict, so we actually aligning a more general flow.
I can't say I analyzed each path from our API that may result with graveler.ErrConflictFound, but I think it is pretty safe, as the handling is done within handleAPIError so the client (no matter which client) gets an error eitherways. I don't think anyone should expect the very general http.StatusInternalServerError explicitly, and fail if another error code is received (excluding the cases where specific error codes gets specific handling, in which case we are only helping the client, IMHO)
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

graveler.ErrNotUnique is returned when attempting to create repo, branch or tag that already exist. Looking at http error codes, it does seem that StatusConflict is the most appropriate code to use. It looks like the usage of both graveler.ErrNotUnique and graveler.ErrConflictFound, and their mapping to http.StatusConflict, are in place

@@ -244,3 +245,49 @@ func TestRevert(t *testing.T) {
body := string(getObjResp.Body)
require.Equal(t, objContent2, body, fmt.Sprintf("path: %s, expected: %s, actual:%s", objPath2, objContent2, body))
}

func TestRevertConflict(t *testing.T) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

minor: Could be a controller level test, it would reduce the runtime.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm all in favour of adding a controller test, but do you think the Esti test should be removed?
As I see it, these E2E tests are the important ones, in terms of CI/CD, as they really cover a true use-case.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added controller UT and remove Esti test

@itaidavid
Copy link
Contributor Author

New responses need to be added to the swagger file too.

swagger.yml added documentration of 409 response for revert. Thanks for pointing this out

@itaidavid itaidavid requested a review from itaiad200 June 22, 2022 22:06
Copy link
Contributor

@itaiad200 itaiad200 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for taking the extra mile with the esti -> controller tests. LGTM

@itaidavid itaidavid merged commit 9ab5e03 into master Jun 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
include-changelog PR description should be included in next release changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Revert confilct returns 500 response
2 participants