Skip to content

Commit e663697

Browse files
committed
GrailsExceptionResolver should not reuse cached controller attribute to find the given error path
1 parent 835e087 commit e663697

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

grace-web-mvc/src/main/groovy/org/grails/web/errors/GrailsExceptionResolver.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class GrailsExceptionResolver extends SimpleMappingExceptionResolver impl
6363
@Override
6464
public ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex) {
6565
// don't reuse cached controller attribute
66+
request.removeAttribute(GrailsApplicationAttributes.CONTROLLER);
6667
request.removeAttribute(GrailsApplicationAttributes.GRAILS_CONTROLLER_CLASS_AVAILABLE);
6768

6869
ex = findWrappedException(ex);
@@ -127,6 +128,7 @@ protected void setStatus(HttpServletRequest request, HttpServletResponse respons
127128
GrailsWrappedRuntimeException gwre = new GrailsWrappedRuntimeException(this.servletContext, e);
128129
mv.addObject(WebUtils.ERROR_EXCEPTION_ATTRIBUTE, gwre);
129130
mv.addObject(WebUtils.EXCEPTION_ATTRIBUTE, gwre);
131+
mv.setStatus(HttpStatusCode.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
130132
}
131133

132134
protected void logStackTrace(Exception e, HttpServletRequest request) {

grace-web-mvc/src/test/groovy/org/grails/web/errors/GrailsExceptionResolverSpec.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import jakarta.servlet.http.HttpServletResponse
44
import jakarta.servlet.http.HttpServletRequest
55

66
import org.apache.groovy.util.Maps
7+
import org.springframework.http.HttpStatusCode
78
import org.springframework.mock.web.MockHttpServletRequest
89
import org.springframework.mock.web.MockHttpServletResponse
910
import org.springframework.validation.SimpleErrors
@@ -30,6 +31,7 @@ class GrailsExceptionResolverSpec extends Specification {
3031

3132
then:
3233
modelAndView.viewName == '/error'
34+
modelAndView.status == HttpStatusCode.valueOf(500)
3335
}
3436

3537
}

0 commit comments

Comments
 (0)