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

add ResponseException#status #756

Merged

Conversation

rursprung
Copy link
Contributor

@rursprung rursprung commented Dec 4, 2023

this allows accessing the HTTP status code of the response when an API returns a ResponseException. this was not possible through getResponse since Response itself is package-private and thus its members (even though they are marked as public) are not accessible to external consumers.

as there's no test coverage for ResponseException i haven't added any for the new API either, as it is a trivial API and it was unclear how adding test coverage for it would fit into the existing test coverage.

solves #749

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

unrelated fun fact: 756 (the PR ID) is the ISO country code for my country 😄🇨🇭

@rursprung
Copy link
Contributor Author

CC @reta & @dblock

Copy link
Member

@dblock dblock left a comment

Choose a reason for hiding this comment

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

Code looks good! Does need a test even if it's just to exercise the code to make sure it really works and we don't accidentally remove it.

@dblock
Copy link
Member

dblock commented Dec 4, 2023

unrelated fun fact: 756 (the PR ID) is the ISO country code for my country 😄🇨🇭

Hopp Schwiiz!!

* Status code returned by Elasticsearch. Shortcut for
* {@code response().status()}.
*/
public int status() {
Copy link
Member

Choose a reason for hiding this comment

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

Q: Should it be status or getStatus? What's the convention?

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 took this 1:1 from OpenSearchException, presuming that this was the accepted convention. happy to change it to getStatus

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've left it at status for now pending your feedback

@rursprung
Copy link
Contributor Author

Does need a test even if it's just to exercise the code to make sure it really works and we don't accidentally remove it.

ok, i've added a small test for it (though i skipped on testing the existing things as buildMessage is just creating a human-readable string, so parsing it in a test is IMHO adding little benefit and getResponse is package-private)

@rursprung rursprung requested review from dblock and reta December 4, 2023 18:04
reta
reta previously approved these changes Dec 4, 2023
this allows accessing the HTTP status code of the response when an API
returns a `ResponseException`. this was not possible through
`getResponse` since `Response` itself is package-private and thus its
members (even though they are marked as `public`) are not accessible to
external consumers.

solves #749

Signed-off-by: Ralph Ursprung <[email protected]>
@rursprung
Copy link
Contributor Author

the test failure is a false reject due to infrastructure issues:

Downloading https://services.gradle.org/distributions/gradle-8.4-bin.zip

Error: Exception in thread "main" java.net.SocketException: Software caused connection abort: socket write error

can you re-trigger it? (i don't have the rights for that)

@rursprung rursprung requested a review from reta December 4, 2023 18:12
@dblock dblock merged commit 863518c into opensearch-project:main Dec 4, 2023
44 of 45 checks passed
@dblock
Copy link
Member

dblock commented Dec 4, 2023

Thanks for doing this @rursprung!

@reta reta added the backport 2.x Backport to 2.x branch label Dec 4, 2023
@opensearch-trigger-bot
Copy link
Contributor

The backport to 2.x failed:

The process '/usr/bin/git' failed with exit code 128

To backport manually, run these commands in your terminal:

# Fetch latest updates from GitHub
git fetch
# Create a new working tree
git worktree add ../.worktrees/backport-2.x 2.x
# Navigate to the new working tree
pushd ../.worktrees/backport-2.x
# Create a new branch
git switch --create backport/backport-756-to-2.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x --mainline 1 863518c372629b70e986eb4f2ae23cdfa482c07e
# Push it to GitHub
git push --set-upstream origin backport/backport-756-to-2.x
# Go back to the original working tree
popd
# Delete the working tree
git worktree remove ../.worktrees/backport-2.x

Then, create a pull request where the base branch is 2.x and the compare/head branch is backport/backport-756-to-2.x.

@dblock
Copy link
Member

dblock commented Dec 4, 2023

@rursprung can you please manually backport it to 2.x so we can ship it sooner than later?

@rursprung rursprung deleted the add-ResponseException.status branch December 4, 2023 19:48
@rursprung
Copy link
Contributor Author

@rursprung can you please manually backport it to 2.x so we can ship it sooner than later?

done. thanks!

reta pushed a commit that referenced this pull request Dec 4, 2023
this allows accessing the HTTP status code of the response when an API
returns a `ResponseException`. this was not possible through
`getResponse` since `Response` itself is package-private and thus its
members (even though they are marked as `public`) are not accessible to
external consumers.

solves #749

Signed-off-by: Ralph Ursprung <[email protected]>
(cherry picked from commit 863518c)
@BrendonFaleiro BrendonFaleiro mentioned this pull request Jun 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport 2.x Backport to 2.x branch
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants