cpoerschke commented on code in PR #2059: URL: https://github.com/apache/solr/pull/2059#discussion_r1385256745
########## solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreaker.java: ########## @@ -54,14 +57,48 @@ public void init(NamedList<?> args) { SolrPluginUtils.invokeSetters(this, args); } - public CircuitBreaker() {} + public CircuitBreaker() { + // Early abort if custom error code system property is wrong + errorCode = resolveExceptionErrorCode(); + } /** Check if circuit breaker is tripped. */ public abstract boolean isTripped(); /** Get error message when the circuit breaker triggers */ public abstract String getErrorMessage(); + /** + * Get http error code, defaults to 429 (TOO_MANY_REQUESTS) but can be overridden with system + * property {@link #SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE} + */ + public static SolrException.ErrorCode getExceptionErrorCode() { + return errorCode; + } + + private static SolrException.ErrorCode resolveExceptionErrorCode() { + int intCode = SolrException.ErrorCode.TOO_MANY_REQUESTS.code; + if (System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE) != null) { + try { + intCode = Integer.parseInt(System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE)); + } catch (NumberFormatException nfe) { + intCode = SolrException.ErrorCode.UNKNOWN.code; + } + } + SolrException.ErrorCode errorCode = SolrException.ErrorCode.getErrorCode(intCode); + if (errorCode != SolrException.ErrorCode.UNKNOWN) { + return errorCode; + } else { + throw new SolrException( + SolrException.ErrorCode.SERVER_ERROR, + String.format( + Locale.ROOT, + "Invalid error code %s specified for circuit breaker system property %s.", + System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE), Review Comment: ```suggestion strCode, ``` ########## solr/core/src/java/org/apache/solr/util/circuitbreaker/CircuitBreaker.java: ########## @@ -54,14 +57,48 @@ public void init(NamedList<?> args) { SolrPluginUtils.invokeSetters(this, args); } - public CircuitBreaker() {} + public CircuitBreaker() { + // Early abort if custom error code system property is wrong + errorCode = resolveExceptionErrorCode(); + } /** Check if circuit breaker is tripped. */ public abstract boolean isTripped(); /** Get error message when the circuit breaker triggers */ public abstract String getErrorMessage(); + /** + * Get http error code, defaults to 429 (TOO_MANY_REQUESTS) but can be overridden with system + * property {@link #SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE} + */ + public static SolrException.ErrorCode getExceptionErrorCode() { + return errorCode; + } + + private static SolrException.ErrorCode resolveExceptionErrorCode() { + int intCode = SolrException.ErrorCode.TOO_MANY_REQUESTS.code; + if (System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE) != null) { + try { + intCode = Integer.parseInt(System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE)); Review Comment: subjective ```suggestion String strCode = System.getProperty(SYSPROP_SOLR_CIRCUITBREAKER_ERRORCODE); if (strCode != null) { try { intCode = Integer.parseInt(strCode); ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org For additional commands, e-mail: issues-h...@solr.apache.org