parent
8e9a553517
commit
6c8fb6c204
|
|
@ -268,6 +268,19 @@ public interface ErrorResponse {
|
|||
*/
|
||||
ErrorResponse build();
|
||||
|
||||
/**
|
||||
* Build the {@code ErrorResponse} instance and also resolve the "detail"
|
||||
* and "title" through the given {@link MessageSource}. Effectively a
|
||||
* shortcut for calling {@link #build()} and then
|
||||
* {@link ErrorResponse#updateAndGetBody(MessageSource, Locale)}.
|
||||
* @since 6.0.3
|
||||
*/
|
||||
default ErrorResponse build(@Nullable MessageSource messageSource, Locale locale) {
|
||||
ErrorResponse response = build();
|
||||
response.updateAndGetBody(messageSource, locale);
|
||||
return response;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ import org.springframework.core.MethodParameter;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.HttpStatusCode;
|
||||
import org.springframework.http.ProblemDetail;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.validation.BindException;
|
||||
import org.springframework.validation.BindingResult;
|
||||
|
|
@ -126,12 +127,12 @@ public class MethodArgumentNotValidException extends BindException implements Er
|
|||
* back on the error's default message.
|
||||
* @since 6.0
|
||||
*/
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public static List<String> errorsToStringList(
|
||||
List<? extends ObjectError> errors, MessageSource source, Locale locale) {
|
||||
List<? extends ObjectError> errors, @Nullable MessageSource source, Locale locale) {
|
||||
|
||||
return errorsToStringList(errors, error -> source.getMessage(
|
||||
error.getCode(), error.getArguments(), error.getDefaultMessage(), locale));
|
||||
return (source != null ?
|
||||
errorsToStringList(errors, error -> source.getMessage(error, locale)) :
|
||||
errorsToStringList(errors));
|
||||
}
|
||||
|
||||
private static List<String> errorsToStringList(
|
||||
|
|
|
|||
|
|
@ -75,6 +75,11 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
|
|||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public MessageSource getMessageSource() {
|
||||
return this.messageSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle all exceptions raised within Spring MVC handling of the request .
|
||||
|
|
|
|||
|
|
@ -96,6 +96,11 @@ public abstract class ResponseEntityExceptionHandler implements MessageSourceAwa
|
|||
this.messageSource = messageSource;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected MessageSource getMessageSource() {
|
||||
return this.messageSource;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Handle all exceptions raised within Spring MVC handling of the request .
|
||||
|
|
|
|||
Loading…
Reference in New Issue