Permalink
Browse files

Merge pull request #3 from fdammassa/master

Enable/disable configuration parameter
  • Loading branch information...
2 parents 767180a + 69f44af commit c3319f8fd69259025315a8c27245a3e20c804538 @fterrier committed Jan 19, 2013
Showing with 26 additions and 18 deletions.
  1. +4 −1 README.md
  2. +1 −0 grails-app/conf/Config.groovy
  3. +21 −17 src/groovy/org/chai/exception/ExceptionHandler.groovy
View
@@ -18,7 +18,10 @@ To install this plugin, run the following:
Configuration
---
-There are 3 variables that need to be configured :
+There are 4 variables that need to be configured :
+
+ // Tells the plugin whether to skip e-mail sending (common case in development environment)
+ mailOnException.enabled = true // or false, enabled by default
// Tells the plugin where the mail should be sent
mailOnException.email.to = "to@example.com"
@@ -5,6 +5,7 @@ log4j = {
'net.sf.ehcache.hibernate'
}
+mailOnException.enabled = true // enabled by default
mailOnException.email.to = "to@example.com"
mailOnException.email.from = "from@example.com"
mailOnException.error.view = "/error"
@@ -46,25 +46,29 @@ class ExceptionHandler extends GrailsExceptionResolver {
def grailsApplication
ModelAndView resolveException(HttpServletRequest request, HttpServletResponse response, Object handler, Exception exception) {
- if (log.debugEnabled) log.debug("resolveException(request=${request}, response=${response}, handler=${handler}, exception=${exception})")
-
- def adminEmail = grailsApplication.config.mailOnException.email.to
- def fromEmail = grailsApplication.config.mailOnException.email.from
- def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.RenderTagLib')
- g.metaClass.prettyPrintStatus = { return '' }
-
- try {
- mailService.sendMail {
- multipart true
- to adminEmail
- from fromEmail
- subject "Unhandled exception in the ${GrailsUtil.environment} environment"
- html g.renderException(exception: exception)
+
+ if(grailsApplication.config.mailOnException.enabled)
+ {
+ if (log.debugEnabled) log.debug("resolveException(request=${request}, response=${response}, handler=${handler}, exception=${exception})")
+
+ def adminEmail = grailsApplication.config.mailOnException.email.to
+ def fromEmail = grailsApplication.config.mailOnException.email.from
+ def g = grailsApplication.mainContext.getBean('org.codehaus.groovy.grails.plugins.web.taglib.RenderTagLib')
+ g.metaClass.prettyPrintStatus = { return '' }
+
+ try {
+ mailService.sendMail {
+ multipart true
+ to adminEmail
+ from fromEmail
+ subject "Unhandled exception in the ${GrailsUtil.environment} environment"
+ html g.renderException(exception: exception)
+ }
+ } catch (Exception e) {
+ if (log.errorEnabled) log.error("could not send email after exception", e)
}
- } catch (Exception e) {
- if (log.errorEnabled) log.error("could not send email after exception", e)
}
-
+
return super.resolveException(request, response, handler, exception)
}
}

0 comments on commit c3319f8

Please sign in to comment.