Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Proper use of SolrResponse.getStatus()

Tags:

solr

solrj

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

Is that true? Is it safe/correct to throw an error when getStatus() returns non-zero? What non-zero values might getStatus() return, and what would those values signify?

like image 819
Adam Rabung Avatar asked Oct 22 '12 21:10

Adam Rabung


2 Answers

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

The possible Values are (according to this, Solr 1.x) set in org.apache.solr.core.SolrCore, in the Method postDecorateResponse (Solr 5.2.1, before that it used to be the Method setResponseHeaderValues), it will use either 500 for general Exceptions or the 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

I end up with passing every response to a check-Method, which will throw an Exception:

private void checkResponse(SolrResponseBase response){
    if(response.getStatus() != 0){
        throw new RuntimeException(String.format("Solr-Response has error code %s",response.getStatus()));
    }
}
like image 53
hinneLinks Avatar answered Sep 30 '22 04:09

hinneLinks


Based on the example usages of getStatus in the article Indexing with SolrJ, I would agree that you can assume that it is safe/correct to throw and error when getStatus() returns a non-zero. Unfortunately, I have not been able to find any references that indicate possible non-zero values that would be returned from getStatus().

like image 27
Paige Cook Avatar answered Sep 30 '22 04:09

Paige Cook