Browse Source

Exceptions thrown from @ExceptionHandler methods logged at warn level (instead of debug)

Issue: SPR-14861
pull/1214/head
Juergen Hoeller 10 years ago
parent
commit
7627c38695
  1. 35
      spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java
  2. 7
      spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java

35
spring-web-reactive/src/main/java/org/springframework/web/reactive/result/method/annotation/RequestMappingHandlerAdapter.java

@ -57,7 +57,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class); private static final Log logger = LogFactory.getLog(RequestMappingHandlerAdapter.class);
private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(10); private final List<HttpMessageReader<?>> messageReaders = new ArrayList<>(10);
private WebBindingInitializer webBindingInitializer; private WebBindingInitializer webBindingInitializer;
@ -74,7 +73,6 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
new ConcurrentHashMap<>(64); new ConcurrentHashMap<>(64);
public RequestMappingHandlerAdapter() { public RequestMappingHandlerAdapter() {
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder())); this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteArrayDecoder()));
this.messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder())); 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, private Mono<HandlerResult> handleException(Throwable ex, HandlerMethod handlerMethod,
BindingContext bindingContext, ServerWebExchange exchange) { BindingContext bindingContext, ServerWebExchange exchange) {
if (ex instanceof Exception) { InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, ex);
InvocableHandlerMethod invocable = findExceptionHandler(handlerMethod, (Exception) ex); if (invocable != null) {
if (invocable != null) { try {
try { if (logger.isDebugEnabled()) {
if (logger.isDebugEnabled()) { logger.debug("Invoking @ExceptionHandler method: " + invocable.getMethod());
logger.debug("Invoking @ExceptionHandler method: " + invocable);
}
invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers());
bindingContext.getModel().clear();
return invocable.invokeForRequest(exchange, bindingContext, ex);
} }
catch (Exception invocationEx) { invocable.setHandlerMethodArgumentResolvers(getArgumentResolvers());
if (logger.isErrorEnabled()) { bindingContext.getModel().clear();
logger.error("Failed to invoke @ExceptionHandler method: " + invocable, invocationEx); 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); return Mono.error(ex);
} }
protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Exception exception) { protected InvocableHandlerMethod findExceptionHandler(HandlerMethod handlerMethod, Throwable exception) {
if (handlerMethod == null) { if (handlerMethod == null) {
return null; return null;
} }
@ -257,8 +254,8 @@ public class RequestMappingHandlerAdapter implements HandlerAdapter, BeanFactory
resolver = new ExceptionHandlerMethodResolver(handlerType); resolver = new ExceptionHandlerMethodResolver(handlerType);
this.exceptionHandlerCache.put(handlerType, resolver); 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); return (method != null ? new InvocableHandlerMethod(handlerMethod.getBean(), method) : null);
} }
} }

7
spring-webmvc/src/main/java/org/springframework/web/servlet/mvc/method/annotation/ExceptionHandlerExceptionResolver.java

@ -26,7 +26,6 @@ import java.util.Map.Entry;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import javax.xml.transform.Source;
import org.springframework.beans.factory.InitializingBean; import org.springframework.beans.factory.InitializingBean;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
@ -381,9 +380,9 @@ public class ExceptionHandlerExceptionResolver extends AbstractHandlerMethodExce
exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, handlerMethod); exceptionHandlerMethod.invokeAndHandle(webRequest, mavContainer, exception, handlerMethod);
} }
} }
catch (Exception invocationEx) { catch (Throwable invocationEx) {
if (logger.isDebugEnabled()) { if (logger.isWarnEnabled()) {
logger.debug("Failed to invoke @ExceptionHandler method: " + exceptionHandlerMethod, invocationEx); logger.warn("Failed to invoke @ExceptionHandler method: " + exceptionHandlerMethod, invocationEx);
} }
return null; return null;
} }

Loading…
Cancel
Save