/** * This constructor gets params for enum result and defaultMsg for a case that params are wrong or * include misleading variables (like empty string) * * @param enumResult - the error to publish * @param defaultMsg - default output when error found in input. * @param params - enumResult additional params */ public ManageDomainsResult( String defaultMsg, ManageDomainsResultEnum enumResult, String... params) { this.exitCode = enumResult.getExitCode(); this.enumResult = enumResult; boolean validParams = true; // setting detailed message // check params validation if (params.length == 0) { log.debug("Wrong exception's params received."); validParams = false; } else { // Verify parameters value for (String param : params) { if (StringUtils.isEmpty(param)) { log.debug("Got null value."); validParams = false; } } } // if all ok. we have params verified if (validParams) { this.detailedMessage = String.format(enumResult.getDetailedMessage(), params); } else { if (StringUtils.isEmpty(defaultMsg)) { this.detailedMessage = enumResult.getDetailedMessage() + ": One of the parameters for this error is null and no default message to show"; } else { this.detailedMessage = defaultMsg; } } }
/** * This constructor is present exception without additional params. we use this one without * additional info, only enum result type with default detailed massage. * * @param enumResult - enum result type */ public ManageDomainsResult(ManageDomainsResultEnum enumResult) { this.exitCode = enumResult.getExitCode(); this.detailedMessage = enumResult.getDetailedMessage(); this.enumResult = enumResult; }