@Documented @Retention(value=RUNTIME) @Target(value={FIELD,METHOD}) public @interface ExposeAsArg
@ExceptionMapping(statusCode=BAD_REQUEST, errorCode="user.exists")
public class UserExistsException extends RuntimeException {
@ExposeAsArg(0) private final String username;
// constructor and etc.
}
With this setting, when the exception happens, the AnnotatedWebErrorHandler
would pick the error code from the annotation and find an appropriate message for the error code.
By annotating the username property with the ExposeAsArg annotation, we can use the username
value to report it in the translated error message:
user.exists=Another user with {0} username is already exists.
When interpolating the error message from the error code, the {0} would be replaced
with the username value exposed with:
@ExposeAsArg(0) private final String username;
ExceptionMapping,
AnnotatedWebErrorHandler| Modifier and Type | Required Element and Description |
|---|---|
int |
value
Determines the index of the to-be-exposed argument.
|
Copyright © 2018. All rights reserved.