Proper use of SolrResponse.getStatus ()

Looking back at the examples on the Internet, I assume that getStatus () returns zero for success and that most failures will manifest as an exception rather than a non-zero error code.

It's true? Is it safe / correct to raise an error when getStatus () returns a nonzero value? What nonzero values ​​can getStatus () return and what do these values ​​mean?

+4
source share
2 answers

I'm not sure if you wold see non-zero code in solrj in general, since in org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpRequestBase, ResponseParser):491 for each non-ok Status Code SolrException will be thrown ( sorlj 5.3.0).

Possible values ​​(according to this , Solr 1.x) set in org.apache.solr.core.SolrCore , in the postDecorateResponse method (Solr 5.2.1, before that it was used as the setResponseHeaderValues method), it will use either 500 for general exceptions , or code of SolrException (see Enum SolrException.ErrorCode ):

 400 - BAD_REQUEST 401 - UNAUTHORIZED 403 - FORBIDDEN 404 - NOT_FOUND 409 - CONFLICT 415 - UNSUPPORTED_MEDIA_TYPE 500 - SERVER_ERROR 503 - SERVICE_UNAVAILABLE 510 - INVALID_STATE 0 - UNKNOWN 

In the end, I pass each response to a validation method that throws an exception:

 private void checkResponse(SolrResponseBase response){ if(response.getStatus() != 0){ throw new RuntimeException(String.format("Solr-Response has error code %s",response.getStatus())); } } 
+2
source

According to the example of using getStatus in the article Indexing with SolrJ , I agree that you can assume that it is safe / correct to throw and error when getStatus () returns a nonzero value. Unfortunately, I could not find links indicating possible non-zero values ​​that would be returned from getStatus ().

0
source

Source: https://habr.com/ru/post/1441389/


All Articles