Skip to content

Commit 5e4eea8

Browse files
committed
Ensure the UrlMappingInfo object is configured correctly for requests originating from response.sendError(..). Fixes #9805
1 parent 7708caa commit 5e4eea8

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/mvc/UrlMappingsHandlerMapping.groovy

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,8 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
125125
protected Object getHandlerInternal(HttpServletRequest request) throws Exception {
126126

127127
def matchedInfo = request.getAttribute(MATCHED_REQUEST)
128-
if(matchedInfo != null) return matchedInfo
128+
def errorStatus = request.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE)
129+
if(matchedInfo != null && errorStatus == null) return matchedInfo
129130

130131
String uri = urlHelper.getPathWithinApplication(request);
131132
def webRequest = GrailsWebRequest.lookup(request)
@@ -134,22 +135,26 @@ class UrlMappingsHandlerMapping extends AbstractHandlerMapping {
134135

135136
String version = findRequestedVersion(webRequest)
136137

137-
def errorStatus = request.getAttribute(WebUtils.ERROR_STATUS_CODE_ATTRIBUTE)
138+
138139
if(errorStatus) {
139140
def exception = request.getAttribute(WebUtils.ERROR_EXCEPTION_ATTRIBUTE)
141+
UrlMappingInfo info
140142
if(exception instanceof Throwable) {
141143
exception = ExceptionUtils.getRootCause(exception)
142144
def exceptionSpecificMatch = urlMappingsHolder.matchStatusCode(errorStatus.toString().toInteger(), (Throwable) exception)
143145
if(exceptionSpecificMatch) {
144-
return exceptionSpecificMatch
146+
info = exceptionSpecificMatch
145147
}
146148
else {
147-
return urlMappingsHolder.matchStatusCode(errorStatus.toString().toInteger())
149+
info = urlMappingsHolder.matchStatusCode(errorStatus.toString().toInteger())
148150
}
149151
}
150152
else {
151-
return urlMappingsHolder.matchStatusCode(errorStatus.toString().toInteger())
153+
info = urlMappingsHolder.matchStatusCode(errorStatus.toString().toInteger())
152154
}
155+
156+
request.setAttribute(MATCHED_REQUEST, info)
157+
return info
153158
}
154159
else {
155160

0 commit comments

Comments
 (0)