Proper use of SolrResponse.getStatus()

solr, solrj

Solution

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()));
    }
}

Problem

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?

Original source