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

Wrong http status assigned to status.FailedPrecondition #146

Closed
pboguslawski opened this issue Mar 6, 2023 · 3 comments · Fixed by #147
Closed

Wrong http status assigned to status.FailedPrecondition #146

pboguslawski opened this issue Mar 6, 2023 · 3 comments · Fixed by #147

Comments

@pboguslawski
Copy link
Contributor

pboguslawski commented Mar 6, 2023

Describe the bug
status.InvalidArgument and status.FailedPrecondition are different statuses but are mapped to the same http.StatusBadRequest:

https://github.com/swaggest/rest/blob/master/error.go#L130
https://github.com/swaggest/usecase/blob/master/status/status.go#L97

Expected behavior
status.FailedPrecondition should be mapped to http.StatusPreconditionFailed.

Additional context
Related: #145

@vearutop
Copy link
Member

vearutop commented Mar 6, 2023

Interesting, original source of mapping is https://github.com/googleapis/googleapis/blob/f36c65081b19e0758ef5696feca27c7dcee5475e/google/rpc/code.proto#L127, I wonder was it a mistake in google repo or deliberate decision.

@pboguslawski
Copy link
Contributor Author

pboguslawski commented Mar 6, 2023

Seems that FAILED_PRECONDITION description in googleapis is not well mapped to HTTP status code (400 means client side problem) or they have some reason for merging different 4xx errors into one 400.

Consider replacing 400->412 in swaggest for status.FailedPrecondition to allow API clients to distinguish failed preconditions (i.e. client tried to update resource with lost update protection detection and update failed) from bad client requests (i.e. invalid argument that may indicate bug in client).

@pboguslawski
Copy link
Contributor Author

After this mod, when 304 is added to possible error responses with...

u.SetExpectedErrors(status.Internal, rest.HTTPCodeAsError(http.StatusNotModified))

...openapi.json contains non-empty body for 304 but should not.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants