Exceptions thrown from @ExceptionHandler methods logged at warn level (instead of debug)
Issue: SPR-14861
This commit is contained in:
parent
9ccffb6de5
commit
7627c38695
|
|
@ -57,7 +57,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
|
|||
|
||||
private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class);
|
||||
|
||||
|
||||
private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(10);
|
||||
|
||||
private WebBindingInitializer webBindingInitializer;
|
||||
|
|
@ -74,7 +73,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
|
|||
new ConcurrentHashMap<>(64);
|
||||
|
||||
|
||||
|
||||
public RequestMappingHandlerAdapter() {
|
||||
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
|
||||
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
|
||||
|
|
@ -226,28 +224,27 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
|
|||
private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod,
|
||||
BindingContext bindingContext, ServerWebExchange exchange) {
|
||||
|
||||
if (ex instanceof Exception) {
|
||||
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, (Exception) ex);
|
||||
if (invocable != null) {
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Invoking @ExceptionHandler method: " + invocable);
|
||||
}
|
||||
invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers());
|
||||
bindingContext.getModel().clear();
|
||||
return invocable.invokeForRequest(exchange, bindingContext, ex);
|
||||
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, ex);
|
||||
if (invocable != null) {
|
||||
try {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Invoking @ExceptionHandler method: " + invocable.getMethod());
|
||||
}
|
||||
catch (Exception invocationEx) {
|
||||
if (logger.isErrorEnabled()) {
|
||||
logger.error("Failed to invoke @ExceptionHandler method: " + invocable, invocationEx);
|
||||
}
|
||||
invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers());
|
||||
bindingContext.getModel().clear();
|
||||
return invocable.invokeForRequest(exchange, bindingContext, ex);
|
||||
}
|
||||
catch (Throwable invocationEx) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to invoke @ExceptionHandler method: " + invocable.getMethod(),
|
||||
invocationEx);
|
||||
}
|
||||
}
|
||||
}
|
||||
return Mono.error(ex);
|
||||
}
|
||||
|
||||
protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Exception exception) {
|
||||
protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Throwable exception) {
|
||||
if (handlerMethod == null) {
|
||||
return null;
|
||||
}
|
||||
|
|
@ -257,8 +254,8 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
|
|||
resolver = new ExceptionHandlerMethodResolver(handlerType);
|
||||
this.exceptionHandlerCache.put(handlerType, resolver);
|
||||
}
|
||||
Method method = resolver.resolveMethod(exception);
|
||||
Method method = resolver.resolveMethodByExceptionType(exception.getClass());
|
||||
return (method != null ? new InvocableHandlerMethod(handlerMethod.getBean(), method) : null);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,7 +26,6 @@ import java.util.Map.Entry;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.transform.Source;
|
||||
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
|
@ -381,9 +380,9 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
|
|||
exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, handlerMethod);
|
||||
}
|
||||
}
|
||||
catch (Exception invocationEx) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Failed to invoke @ExceptionHandler method: " + exceptionHandlerMethod, invocationEx);
|
||||
catch (Throwable invocationEx) {
|
||||
if (logger.isWarnEnabled()) {
|
||||
logger.warn("Failed to invoke @ExceptionHandler method: " + exceptionHandlerMethod, invocationEx);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue