Skip to content

Commit 24db59d

Browse files
committed
refactor: decouple further response processing in exception resolving
1 parent 8e0b9ca commit 24db59d

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* https://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.grails.buffer
21+
22+
/**
23+
* Interface to assign to a HttpServletResponse wrapper so on an error, it can be deactivated to not further
24+
* change the response.
25+
*/
26+
interface GrailsResponseMutator {
27+
/**
28+
* Do not mutate the response & stop any processing of it.
29+
*/
30+
void deactivateResponseMutator();
31+
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.apache.commons.logging.LogFactory;
3636
import org.codehaus.groovy.control.CompilationFailedException;
3737
import grails.core.GrailsApplication;
38+
import org.grails.buffer.GrailsResponseMutator;
3839
import org.grails.exceptions.reporting.DefaultStackTraceFilterer;
3940
import org.grails.core.exceptions.GrailsRuntimeException;
4041
import org.grails.exceptions.reporting.StackTraceFilterer;
@@ -194,6 +195,10 @@ protected ModelAndView resolveViewOrForward(Exception ex, UrlMappingsHolder urlM
194195
else if (info != null && info.getControllerName() != null) {
195196
String uri = determineUri(request);
196197
if (!response.isCommitted()) {
198+
if (response instanceof GrailsResponseMutator) {
199+
// prevent further mutation of the request since an error page needs rendered instead
200+
((GrailsResponseMutator) response).deactivateResponseMutator();
201+
}
197202
forwardRequest(info, request, response, mv, uri);
198203
// return an empty ModelAndView since the error handler has been processed
199204
return new ModelAndView();

0 commit comments

Comments
 (0)