@@ -19,6 +19,8 @@ | |||
*/ | |||
package org.sonar.server.exceptions; | |||
import javax.annotation.Nullable; | |||
/** | |||
* Request is not valid and can not be processed. | |||
*/ | |||
@@ -30,8 +32,16 @@ public class BadRequestException extends HttpException { | |||
super(BAD_REQUEST, message); | |||
} | |||
public BadRequestException(String l10nKey, Object... l10nParams) { | |||
super(BAD_REQUEST, l10nKey, l10nParams); | |||
public BadRequestException(@Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) { | |||
super(BAD_REQUEST, message, l10nKey, l10nParams); | |||
} | |||
public static BadRequestException of(String message) { | |||
return new BadRequestException(message); | |||
} | |||
public static BadRequestException ofL10n(String l10nKey, Object... l10nParams) { | |||
return new BadRequestException(null, l10nKey, l10nParams); | |||
} | |||
} |
@@ -20,6 +20,7 @@ | |||
package org.sonar.server.exceptions; | |||
import javax.annotation.CheckForNull; | |||
import javax.annotation.Nullable; | |||
public class HttpException extends RuntimeException { | |||
private final int httpCode; | |||
@@ -36,7 +37,8 @@ public class HttpException extends RuntimeException { | |||
this.httpCode = httpCode; | |||
} | |||
public HttpException(int httpCode, String l10nKey, Object... l10nParams) { | |||
public HttpException(int httpCode, @Nullable String message, @Nullable String l10nKey, @Nullable Object[] l10nParams) { | |||
super(message); | |||
this.httpCode = httpCode; | |||
this.l10nKey = l10nKey; | |||
this.l10nParams = l10nParams; |
@@ -584,20 +584,20 @@ public class InternalRubyIssueService implements ServerComponent { | |||
private void checkMandatoryParameter(String value, String paramName) { | |||
if (Strings.isNullOrEmpty(value)) { | |||
throw new BadRequestException("errors.cant_be_empty", paramName); | |||
throw BadRequestException.ofL10n("errors.cant_be_empty", paramName); | |||
} | |||
} | |||
private void checkMandatorySizeParameter(String value, String paramName, Integer size) { | |||
checkMandatoryParameter(value, paramName); | |||
if (!Strings.isNullOrEmpty(value) && value.length() > size) { | |||
throw new BadRequestException("errors.is_too_long", paramName, size); | |||
throw BadRequestException.ofL10n("errors.is_too_long", paramName, size); | |||
} | |||
} | |||
private void checkOptionalSizeParameter(String value, String paramName, Integer size) { | |||
if (!Strings.isNullOrEmpty(value) && value.length() > size) { | |||
throw new BadRequestException("errors.is_too_long", paramName, size); | |||
throw BadRequestException.ofL10n("errors.is_too_long", paramName, size); | |||
} | |||
} | |||