SOLR-7243: Return more informative error from CloudSolrServer when available.

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1679099 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shawn Heisey 2015-05-12 21:32:14 +00:00
parent 2011dbedab
commit b75b546110
3 changed files with 30 additions and 3 deletions

View File

@ -348,6 +348,11 @@ Other Changes
* SOLR-7500: Remove pathPrefix from SolrDispatchFilter as Solr no longer runs as a part
of a bigger webapp. (Anshum Gupta)
* SOLR-7243: CloudSolrClient was always returning SERVER_ERROR for exceptions,
even when a more relevant ErrorCode was available, via SolrException. Now
the actual ErrorCode is used when available.
(Hrishikesh Gadre via Shawn Heisey)
================== 5.1.0 ==================
Consult the LUCENE_CHANGES.txt file for additional, low level, changes in this release

View File

@ -18,6 +18,7 @@ package org.apache.solr.schema;
import org.apache.solr.SolrTestCaseJ4.SuppressSSL;
import org.apache.solr.client.solrj.SolrClient;
import org.apache.solr.client.solrj.impl.CloudSolrClient;
import org.apache.solr.client.solrj.impl.HttpSolrClient;
import org.apache.solr.cloud.AbstractFullDistribZkTestBase;
import org.apache.solr.common.SolrException;
@ -187,6 +188,15 @@ public class TestCloudSchemaless extends AbstractFullDistribZkTestBase {
} catch (SolrException se) {
assertEquals(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode(se.code()));
}
try {
CloudSolrClient cloudSolrClient = getCommonCloudSolrClient();
cloudSolrClient.add(docs);
cloudSolrClient.commit();
fail("Expected Bad Request Exception");
} catch (SolrException ex) {
assertEquals(ErrorCode.BAD_REQUEST, ErrorCode.getErrorCode((ex).code()));
}
}
}
}

View File

@ -619,7 +619,13 @@ public class CloudSolrClient extends SolrClient {
}
if (exceptions.size() > 0) {
throw new RouteException(ErrorCode.SERVER_ERROR, exceptions, routes);
Throwable firstException = exceptions.getVal(0);
if(firstException instanceof SolrException) {
SolrException e = (SolrException) firstException;
throw new RouteException(ErrorCode.getErrorCode(e.code()), exceptions, routes);
} else {
throw new RouteException(ErrorCode.SERVER_ERROR, exceptions, routes);
}
}
} else {
for (Map.Entry<String, LBHttpSolrClient.Req> entry : routes.entrySet()) {
@ -629,7 +635,11 @@ public class CloudSolrClient extends SolrClient {
NamedList<Object> rsp = lbClient.request(lbRequest).getResponse();
shardResponses.add(url, rsp);
} catch (Exception e) {
throw new SolrServerException(e);
if(e instanceof SolrException) {
throw (SolrException) e;
} else {
throw new SolrServerException(e);
}
}
}
}
@ -928,7 +938,9 @@ public class CloudSolrClient extends SolrClient {
log.warn("Re-trying request to collection(s) "+collection+" after stale state error from server.");
resp = requestWithRetryOnStaleState(request, retryCount+1, collection);
} else {
if (exc instanceof SolrServerException) {
if(exc instanceof SolrException) {
throw exc;
} if (exc instanceof SolrServerException) {
throw (SolrServerException)exc;
} else if (exc instanceof IOException) {
throw (IOException)exc;