} catch (SolrException e) { if (e.code() != 400) { throw new IOException(e);
private boolean isDocumentIssue(SolrException e) { return e.code() == ErrorCode.BAD_REQUEST.code; }
private boolean isDocumentIssue(SolrException e) { return e.code() == ErrorCode.BAD_REQUEST.code; }
private boolean isDocumentIssue(SolrException e) { return e.code() == ErrorCode.BAD_REQUEST.code; }
private boolean isDocumentIssue(SolrException e) { return e.code() == ErrorCode.BAD_REQUEST.code; }
@Override public boolean test(Throwable t) { return (t instanceof IOException || t instanceof SolrServerException || (t instanceof SolrException && ELIGIBLE_CODES.contains(((SolrException) t).code()))); } }
@Override public RetryPolicy getRetryPolicy(Throwable exception, SolrRequest request, SolrClient server, RetryPolicy currentPolicy) { if (exception instanceof SolrException) { SolrException sex = (SolrException) exception; if (sex.code() == ErrorCode.UNAUTHORIZED.code) { return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } if (sex.code() == ErrorCode.UNSUPPORTED_MEDIA_TYPE.code) { return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } if (sex.getMessage().startsWith("undefined field")) { // schema.xml mismatch, see IndexSchema.java return RetryPolicyFactory.DONT_RETRY; // no point retrying that - would never succeed } } if (currentPolicy == null) { return initialRetryPolicy; // init } else { return currentPolicy; // continue with current policy } }
protected void sendError(HttpServletResponse res, Throwable ex) throws IOException { int code=500; String trace = ""; if( ex instanceof SolrException ) { code = ((SolrException)ex).code(); } // For any regular code, don't include the stack trace if( code == 500 || code < 100 ) { StringWriter sw = new StringWriter(); ex.printStackTrace(new PrintWriter(sw)); trace = "\n\n"+sw.toString(); SolrException.logOnce(log,null,ex ); // non standard codes have undefined results with various servers if( code < 100 ) { log.warn( "invalid return code: "+code ); code = 500; } } res.sendError( code, ex.getMessage() + trace ); }
public static void waitForNon403or404or503(HttpSolrClient collectionClient) throws Exception { SolrException exp = null; final TimeOut timeout = new TimeOut(30, TimeUnit.SECONDS, TimeSource.NANO_TIME); while (! timeout.hasTimedOut()) { boolean missing = false; try { collectionClient.query(new SolrQuery("*:*")); } catch (SolrException e) { if (!(e.code() == 403 || e.code() == 503 || e.code() == 404)) { throw e; } exp = e; missing = true; } if (!missing) { return; } Thread.sleep(50); } fail("Could not find the new collection - " + exp.code() + " : " + collectionClient.getBaseURL()); }
/** Makes sure a query throws a SolrException with the listed response code */ public void assertQEx(String message, SolrQueryRequest req, int code ) { try { h.query(req); fail( message ); } catch (SolrException sex) { assertEquals( code, sex.code() ); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } }
if (e.code() == SolrException.ErrorCode.SERVER_ERROR.code) {
/** Makes sure a query throws a SolrException with the listed response code */ public static void assertQEx(String message, SolrQueryRequest req, int code ) { try { ignoreException("."); h.query(req); fail( message ); } catch (SolrException sex) { assertEquals( code, sex.code() ); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } finally { unIgnoreException("."); } }
public static void assertQEx(String message, SolrQueryRequest req, SolrException.ErrorCode code ) { try { ignoreException("."); h.query(req); fail( message ); } catch (SolrException e) { assertEquals( code.code, e.code() ); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } finally { unIgnoreException("."); } } /**
/** * Makes sure a query throws a SolrException with the listed response code and expected message * @param failMessage The assert message to show when the query doesn't throw the expected exception * @param exceptionMessage A substring of the message expected in the exception * @param req Solr request * @param code expected error code for the query */ public static void assertQEx(String failMessage, String exceptionMessage, SolrQueryRequest req, SolrException.ErrorCode code ) { try { ignoreException("."); h.query(req); fail( failMessage ); } catch (SolrException e) { assertEquals( code.code, e.code() ); assertTrue("Unexpected error message. Expecting \"" + exceptionMessage + "\" but got \"" + e.getMessage() + "\"", e.getMessage()!= null && e.getMessage().contains(exceptionMessage)); } catch (Exception e2) { throw new RuntimeException("Exception during query", e2); } finally { unIgnoreException("."); } }
if (!isNonRetryable && RETRY_CODES.contains(e.code())) { ex = (!isZombie) ? addZombie(client, e) : e; } else {
solrException.getCause()); } else { ErrorCode errorCode = SolrException.ErrorCode.getErrorCode(solrException.code()); switch (errorCode) { case NOT_FOUND:
srsp.setException(th); if (th instanceof SolrException) { srsp.setResponseCode(((SolrException)th).code()); } else { srsp.setResponseCode(-1);
@Test public void testRetryOfBadRequest() throws Exception { SolrInputDocument doc = new SolrInputDocument(); // bad doc is missing 'id' field // without RetryingSolrServer try { solrServer.add(doc); fail(); } catch (SolrException e) { assertEquals(ErrorCode.BAD_REQUEST.code, e.code()); } // RetryingSolrServer, retry twice CountingSolrServer countingSolrServer = new CountingSolrServer(solrServer); SolrClient solr = new RetryingSolrServer(countingSolrServer, getRetryTwicePolicyFactory(), getMetricsFacade()); try { solr.add(doc); fail(); } catch (RetriesExhaustedException e) { Assert.assertEquals(3, countingSolrServer.getNumRequests()); Assert.assertTrue(e.getCause() instanceof SolrException); SolrException sex = (SolrException) e.getCause(); Assert.assertEquals(ErrorCode.BAD_REQUEST.code, sex.code()); } }
if( exception != null ){ if( exception instanceof SolrException ) status = ((SolrException)exception).code(); else status = 500;