-
Notifications
You must be signed in to change notification settings - Fork 25.3k
Use status code 500 for errors if no shard failed #88551
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
Use status code 500 for errors if no shard failed #88551
Conversation
If there is no shard failure we would like to use a generic Internal Server Error other than a Service Unavailable. Moreover, if the cause is known we use a status code that reflects the cause. Resolves elastic#20004
Pinging @elastic/es-search (Team:Search) |
Hi @salvatore-campagna, I've created a changelog YAML for you. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally the code looks good. I have left a minor comment.
However, I must admit I am not an expert on the related code. So @nik9000 or @not-napoleon could have a better opinion here.
RestStatus status = shardFailures[0].status(); | ||
if (shardFailures.length > 1) { | ||
for (int i = 1; i < shardFailures.length; i++) { | ||
if (shardFailures[i].status().getStatus() >= 500) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of the hardcoded 500
value here.
Is there any way to add a constant such as RestStatus.INTERNAL_SERVER_ERROR.getStatus()
Also, should you perhaps delegate this to the RestStatus.status()
method?
Would running something like RestStatus.status(0, shardFailures.length, shardFailures)
return the same result? Again, I am not an expert on this part of the code, so take this with a grain of salt.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Left a couple of nits, but I think this is a fine approach.
@@ -161,4 +161,8 @@ public String toString() { | |||
public String getPhaseName() { | |||
return phaseName; | |||
} | |||
|
|||
public ShardSearchFailure[] getShardFailures() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this could be package scoped?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like there is already a method shardFailures()
which I didn't see...so I will use the existing one and get rid of the one I added.
} | ||
} | ||
return status; | ||
return super.status(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's much better :)
Heya, have we thought about possible consequences in clients code around changing the status code here? I've seen this is marked bug hence it is not considered a breaking change, I assume. But was this discussed before merging? |
If there is no shard failure we would like to use a generic
Internal Server Error other than a Service Unavailable.
Moreover, if the cause is known we use a status code that
reflects the cause.
Resolves #20004