Search in sources :

Example 1 with ErrorCode

use of org.apache.solr.common.SolrException.ErrorCode in project lucene-solr by apache.

the class IgnoreCommitOptimizeUpdateProcessorFactory method init.

@Override
public void init(final NamedList args) {
    SolrParams params = (args != null) ? SolrParams.toSolrParams(args) : null;
    if (params == null) {
        // default is 403 error
        errorCode = ErrorCode.FORBIDDEN;
        responseMsg = DEFAULT_RESPONSE_MSG;
        ignoreOptimizeOnly = false;
        return;
    }
    ignoreOptimizeOnly = params.getBool("ignoreOptimizeOnly", false);
    int statusCode = params.getInt("statusCode", ErrorCode.FORBIDDEN.code);
    if (statusCode == 200) {
        // not needed but makes the logic clearer
        errorCode = null;
        // OK to be null for 200's
        responseMsg = params.get("responseMessage");
    } else {
        errorCode = ErrorCode.getErrorCode(statusCode);
        if (errorCode == ErrorCode.UNKNOWN) {
            // only allow the error codes supported by the SolrException.ErrorCode class
            StringBuilder validCodes = new StringBuilder();
            int appended = 0;
            for (ErrorCode code : ErrorCode.values()) {
                if (code != ErrorCode.UNKNOWN) {
                    if (appended++ > 0)
                        validCodes.append(", ");
                    validCodes.append(code.code);
                }
            }
            throw new IllegalArgumentException("Configured status code " + statusCode + " not supported! Please choose one of: " + validCodes.toString());
        }
        // must always have a response message if sending an error code
        responseMsg = params.get("responseMessage", DEFAULT_RESPONSE_MSG);
    }
}
Also used : SolrParams(org.apache.solr.common.params.SolrParams) ErrorCode(org.apache.solr.common.SolrException.ErrorCode)

Aggregations

ErrorCode (org.apache.solr.common.SolrException.ErrorCode)1 SolrParams (org.apache.solr.common.params.SolrParams)1