Skip to content

[BUG] Wrong http code returned from create index API with bad input. #2756

@mch2

Description

@mch2

Describe the bug
Create Index API returning wrong http response code when given invalid input.

To Reproduce

  1. Start up server ./gradlew run
  2. Send a curl request to create an index with invalid input
curl -v -X PUT "localhost:9200/test-index?pretty" -H 'Content-Type: application/json' -d'
adksjhfakldhsf
'

Response:

*   Trying 127.0.0.1...
* TCP_NODELAY set
* Connected to localhost (127.0.0.1) port 9200 (#0)
> PUT /test-index?pretty HTTP/1.1
> Host: localhost:9200
> User-Agent: curl/7.64.1
> Accept: */*
> Content-Type: application/json
> Content-Length: 16
>
* upload completely sent off: 16 out of 16 bytes
< HTTP/1.1 500 Internal Server Error
< content-type: application/json; charset=UTF-8
< content-length: 390
<
{
  "error" : {
    "root_cause" : [
      {
        "type" : "not_x_content_exception",
        "reason" : "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
      }
    ],
    "type" : "not_x_content_exception",
    "reason" : "Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes"
  },
  "status" : 500
}
* Connection #0 to host localhost left intact
* Closing connection 0

Expected behavior
This should return http 400 Bad Request.

Plugins
None

Host/Environment (please complete the following information):

  • OS: [e.g. iOS]. Mac
  • Version [e.g. 22] 2.1.0 (current main)

Metadata

Metadata

Assignees

Labels

Indexing & SearchbugSomething isn't workinggood first issueGood for newcomershacktoberfestGlobal event that encourages people to contribute to open-source.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions