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

Handle exceptions thrown from RestCompatibleVersionHelper #80253

Merged
merged 6 commits into from
Nov 10, 2021

Conversation

pgomulka
Copy link
Contributor

@pgomulka pgomulka commented Nov 3, 2021

RestCompatibleVersionHelper is used to validate versions on Accept and Content-Type headers
When a validation fails, an exception is being thrown indicating which headers are incorrect.
That exception was not handled in RestRequest where the helper was used.
This commit gracefully handles the exception from validation failure. A bad request response is returned to a user.

closes #79060
closes #78214

@pgomulka pgomulka added the WIP label Nov 3, 2021
@pgomulka pgomulka self-assigned this Nov 3, 2021
@pgomulka pgomulka changed the title handle exceptions thrown from RestCompatibleVersionHelper Handle exceptions thrown from RestCompatibleVersionHelper Nov 5, 2021
@pgomulka pgomulka added :Core/Infra/REST API REST infrastructure and utilities v8.0.0 and removed WIP labels Nov 5, 2021
@pgomulka pgomulka marked this pull request as ready for review November 5, 2021 12:01
@elasticmachine elasticmachine added the Team:Core/Infra Meta label for core/infra team label Nov 5, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

// e.getMessage(),
// equalTo("Unknown media type Accept=wrong/type;compatible-with=")
// );
// }
Copy link
Contributor

Choose a reason for hiding this comment

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

This part right here seems off. Perhaps accidentally committed? WIP that was meant to be removed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ah yes, initially I thought I can include validation for unknown media types before parsing versions, but this is far beyond the scope of this PR.

super(cause);
this.failedHeaderName = failedHeaderName;
this.failedHeaderNames = Set.of(failedHeaderNames);
this.message = "Invalid media-type value on header " + this.failedHeaderNames;
Copy link
Contributor

Choose a reason for hiding this comment

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

Little wording/formatting nit -- maybe "on headers [HeaderA, HeaderB, HeaderC]"? What do you think?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

agree - plural looks better. I guess for single header that failed it is fine too?
example: Invalid media-type value on headers [Content-Type]
I rely on AbstractCollection.toString here when it comes to set formatting

Copy link
Contributor

@jakelandis jakelandis left a comment

Choose a reason for hiding this comment

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

LGTM

@pgomulka pgomulka added the auto-backport-and-merge Automatically create backport pull requests and merge when ready label Nov 10, 2021
@pgomulka pgomulka merged commit 5e98ea4 into elastic:master Nov 10, 2021
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.0 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 80253

pgomulka added a commit to pgomulka/elasticsearch that referenced this pull request Nov 10, 2021
)

RestCompatibleVersionHelper is used to validate versions on Accept and Content-Type headers
When a validation fails, an exception is being thrown indicating which headers are incorrect.
That exception was not handled in RestRequest where the helper was used.
This commit gracefully handles the exception from validation failure. A bad request response is returned to a user.

closes elastic#79060
closes elastic#78214
elasticsearchmachine pushed a commit that referenced this pull request Nov 10, 2021
…80605)

RestCompatibleVersionHelper is used to validate versions on Accept and Content-Type headers
When a validation fails, an exception is being thrown indicating which headers are incorrect.
That exception was not handled in RestRequest where the helper was used.
This commit gracefully handles the exception from validation failure. A bad request response is returned to a user.

closes #79060
closes #78214
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport-and-merge Automatically create backport pull requests and merge when ready >bug :Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team v8.0.0-rc1 v8.1.0
Projects
None yet
6 participants