hashicorp / consul

Consul is a distributed, highly available, and data center aware solution to connect and configure applications across dynamic, distributed infrastructure.
https://www.consul.io
Other
28.33k stars 4.42k forks source link

ambiguous status codes makes it difficult to reason about api errors #6711

Open nicholasamorim opened 4 years ago

nicholasamorim commented 4 years ago

When filing a bug, please include the following headings if possible. Any example text in this template can be deleted.

Overview of the Issue

When calling the API to POST a prepared query, it returns 500 if it already exists. The correct would be to return 409 Conflict.

The body message makes it clear that the query already has been created but the 500 return code is less than ideal.

Not only it's semantically wrong but it also makes it harder to reason with in automated logic as 5xx is reserved for Server Errors.

Reproduction Steps

  1. Call
curl http://127.0.0.1:8500/v1/query \
    --request POST \
    --data \
'{
  "Name": "test",
  "Service": {
    "Service": "test",
    "Failover": {
      "NearestN": 2
    }
  }
}'
  1. Then call it again.
schristoff commented 4 years ago

Just commenting here that this will be kept open and used to focus on reworking our HTTP status codes we return to follow the more standardized approach.