In Grails app, occasionally seeing "Cannot issue redirect" in logs:
2011-04-27 12:18:40,469 [TP-Processor13] ERROR GrailsExceptionResolver - Cannot issue a redirect(..) here. A previous call to redirect(..) has already redirected the response. org.codehaus.groovy.grails.web.servlet.mvc.exceptions.CannotRedirectException: Cannot issue a redirect(..) here. A previous call to redirect(..) has already redirected the response. at com.coach.LoginController$_closure2.doCall(LoginController.groovy:90) ...
Not sure how to track this down. Any ideas or suggestions?
Todd
Check the login controller; it seems like you are not returning from the action after redirect. E.g.:
if (some condition) {
redirect ()
return // should return from here to finish the action, otherwise the rest of the code will be executed
}
Although this question has been answered, I figured I'd share my experience for future trawlers. Hope it helps.
This happened to me because I wasn't doing a return
after the redirect:
if (test) {
flash.message = "Error message."
redirect(action: "list")
}
switch ( params.test ) {
case "value":
redirect(action: "value", id: callInstance.id, version: callInstance.version)
After a redirect, Grails will keep going if there's no return
. In my case, it hit the switch
and went on to the second redirect, which is where the error arose. The code should look like the following:
if (test) {
flash.message = "Error message."
redirect(action: "list")
return
}
switch ( params.test ) {
case "value":
redirect(action: "value", id: callInstance.id, version: callInstance.version)
return
This code has been anonymised of course ;)
EDIT
Aw geeze. I just realized that this is Sachin's answer :/ Well, I'll leave it as an additional example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With