Created
November 29, 2012 08:51
-
-
Save joeRinehart/4167671 to your computer and use it in GitHub Desktop.
Grails Error Handling
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grails> create-controller Error |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Application Error - Development View</title> | |
<meta name="layout" content="bootstrap"> | |
<meta name="bootstrap" content="main"> | |
<link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css"> | |
</head> | |
<body> | |
<p><em>This is a development view of an error, and would not be shown in production.</em></p> | |
<g:renderException exception="${exception}" /> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.grails.commons.GrailsApplication | |
import grails.util.GrailsUtil | |
class ErrorController { | |
def index() { | |
if ( GrailsApplication.ENV_PRODUCTION == GrailsUtil.environment ) { | |
// Production: show a nice error message | |
render(view:'production') | |
} else { | |
// Not it production? show an ugly, developer-focused error message | |
render(view:'development') | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.grails.commons.GrailsApplication | |
import grails.util.GrailsUtil | |
class ErrorController { | |
def index() { | |
// "Do stuff" with the exception: | |
Exception exception = request.exception | |
println "Here's what happened: ${exception}" | |
if ( GrailsApplication.ENV_PRODUCTION == GrailsUtil.environment ) { | |
// Production: show a nice error message | |
render(view:'production') | |
} else { | |
// Not it production? show an ugly, developer-focused error message | |
render(view:'development') | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.codehaus.groovy.grails.commons.GrailsApplication | |
import grails.util.GrailsUtil | |
class ErrorController { | |
def index() { | |
try { | |
// "Do stuff" with the exception: | |
Exception exception = request.exception | |
println "Here's what happened: ${exception}" | |
if ( GrailsApplication.ENV_PRODUCTION == GrailsUtil.environment ) { | |
// Production: show a nice error message | |
render(view:'production') | |
} else { | |
// Not it production? show an ugly, developer-focused error message | |
render(view:'development') | |
} | |
} catch ( Exception e ) { | |
render(view: 'unhandleable') | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<title>Application Error</title> | |
<meta name="layout" content="bootstrap"> | |
<meta name="bootstrap" content="main"> | |
<link rel="stylesheet" href="${resource(dir: 'css', file: 'errors.css')}" type="text/css"> | |
</head> | |
<body> | |
<h1>Application Error</h1> | |
<p>We're sorry, but the application has encountered an error. Please try again.</p> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class UrlMappings { | |
static mappings = { | |
/* other stuff.... */ | |
"500"(controller: "error") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment