Skip to content

Commit

Permalink
refactor extract-method to throw solrexception
Browse files Browse the repository at this point in the history
  • Loading branch information
aparnasuresh85 committed Dec 7, 2023
1 parent 4bde528 commit 8ebc739
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.lucene.index.ExitableDirectoryReader;
import org.apache.lucene.search.TotalHits;
import org.apache.solr.client.solrj.SolrRequest.SolrRequestType;
import org.apache.solr.client.solrj.SolrResponse;
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.cloud.ZkController;
import org.apache.solr.common.SolrDocumentList;
Expand Down Expand Up @@ -580,12 +581,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
// If things are not tolerant, abort everything and rethrow
if (!tolerant) {
shardHandler1.cancelAll();
if (srsp.getException() instanceof SolrException) {
throw (SolrException) srsp.getException();
} else {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR, srsp.getException());
}
throwSolrException(srsp.getException());
} else {
// Check if the purpose includes 'PURPOSE_GET_TOP_IDS'
boolean includesTopIdsPurpose =
Expand All @@ -598,7 +594,7 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
boolean allShardsFailed = includesTopIdsPurpose && allResponsesHaveExceptions;
// if all shards fail, fail the request despite shards.tolerant
if (allShardsFailed) {
throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, srsp.getException());
throwSolrException(srsp.getException());
} else {
rsp.getResponseHeader()
.asShallowMap()
Expand Down Expand Up @@ -663,6 +659,15 @@ public void handleRequestBody(SolrQueryRequest req, SolrQueryResponse rsp) throw
}
}

public static void throwSolrException(Throwable shardResponseException) throws SolrException {
if (shardResponseException instanceof SolrException) {
throw (SolrException) shardResponseException;
} else {
throw new SolrException(
SolrException.ErrorCode.SERVER_ERROR, shardResponseException);
}
}

private void tagRequestWithRequestId(ResponseBuilder rb) {
final boolean ridTaggingDisabled =
rb.req.getParams().getBool(CommonParams.DISABLE_REQUEST_ID, DISABLE_REQUEST_ID_DEFAULT);
Expand Down

0 comments on commit 8ebc739

Please sign in to comment.