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?
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()));
}
}
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().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With