Skip to content

Commit

Permalink
opensearch-project#4687 - change rest status to 404 if not found
Browse files Browse the repository at this point in the history
Signed-off-by: p1729 <pankajkumar1729@gmail.com>
  • Loading branch information
p1729 committed Oct 7, 2022
1 parent 9aa794f commit e9de279
Showing 1 changed file with 10 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import org.opensearch.OpenSearchException;
import org.opensearch.common.io.stream.StreamInput;
import org.opensearch.common.io.stream.StreamOutput;
import org.opensearch.rest.RestStatus;

import java.io.IOException;

Expand Down Expand Up @@ -69,6 +70,15 @@ public RepositoryException(StreamInput in) throws IOException {
repository = in.readOptionalString();
}

@Override
public RestStatus status() {
String causeDescription = unwrapCause().getMessage();
if (causeDescription != null && causeDescription.contains("not found")) {
return RestStatus.NOT_FOUND;
}
return RestStatus.INTERNAL_SERVER_ERROR;
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
Expand Down

0 comments on commit e9de279

Please sign in to comment.