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

[Rest Api Compatibility] content-type headers are not vendor specific when exception is returned #92658

Closed
pgomulka opened this issue Jan 4, 2023 · 2 comments
Labels
>bug :Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team

Comments

@pgomulka
Copy link
Contributor

pgomulka commented Jan 4, 2023

Elasticsearch Version

8.5

Installed Plugins

No response

Java Version

bundled

OS Version

macos

Problem Description

when an exception like 404 not found is returned a response content type is not vendor specific even though the Accept header was vnd specific on a request.

Steps to Reproduce

send a request to a non existing index
curl -k --request GET -u elastic:f2RROKkV5m_2P+VCMYdU --url https://localhost:9200/missing/_search --header 'Content-Type: application/vnd.elasticsearch+json;compatible-with=8' --header 'Accept: application/vnd.elasticsearch+json;compatible-with=8' -v

response
< HTTP/1.1 404 Not Found
< X-elastic-product: Elasticsearch
< content-type: application/json;charset=utf-8
< content-length: 371
<

  • Connection #0 to host localhost left intact
    {"error":{"root_cause":[{"type":"index_not_found_exception","reason":"no such index [missing]","resource.type":"index_or_alias","resource.id":"missing","index_uuid":"na","index":"missing"}],"type":"index_not_found_exception","reason":"no such index [missing]","resource.type":"index_or_alias","resource.id":"missing","index_uuid":"na","index":"missing"},"status":404}%

I think this is due to error handling was not implemented fully with rest api compatibility project.
the fix should change

this.responseMediaType = builder.contentType().mediaType();

--- a/server/src/main/java/org/elasticsearch/rest/RestResponse.java
+++ b/server/src/main/java/org/elasticsearch/rest/RestResponse.java
@@ -122,7 +122,7 @@ public class RestResponse {
         try (XContentBuilder builder = channel.newErrorBuilder()) {
             build(builder, params, status, channel.detailedErrorsEnabled(), e);
             this.content = BytesReference.bytes(builder);
-            this.responseMediaType = builder.contentType().mediaType();
+            this.responseMediaType = builder.getResponseContentTypeString();
         }

Logs (if relevant)

No response

@pgomulka pgomulka added >bug :Core/Infra/REST API REST infrastructure and utilities needs:triage Requires assignment of a team area label labels Jan 4, 2023
@elasticsearchmachine elasticsearchmachine added Team:Core/Infra Meta label for core/infra team and removed needs:triage Requires assignment of a team area label labels Jan 4, 2023
@elasticsearchmachine
Copy link
Collaborator

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

@pgomulka
Copy link
Contributor Author

pgomulka commented Jan 4, 2023

a similar problem occurs in EQL
extracted this comment to a new issue #92710

pgomulka added a commit to pgomulka/elasticsearch that referenced this issue Jan 5, 2023
Currently a response media type when returning an exception to user was taken from
XContentType.mediaType - hardcoded values.
Response media type should be formatted with parameters (when provided).

relates elastic#92658
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
>bug :Core/Infra/REST API REST infrastructure and utilities Team:Core/Infra Meta label for core/infra team
Projects
None yet
Development

No branches or pull requests

2 participants