Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Email Notification from Grails on Grails Error

Tags:

grails

Is there a way to send myself the details anytime a Grails Error happens on a Grails site? What is the best way to set this up? In one place? (trying to stay DRY)

And I would like to include the URL that produced the error.

like image 599
BuddyJoe Avatar asked Dec 08 '11 18:12

BuddyJoe


1 Answers

. If you intend to catch any Exception happening on your project and mail it, well i am using such setup, and i did it in the following way: .

  1. Created a Tag in the TagLib:

    def reportError = {attrs, body ->
            String error = body()
            //error will have the Error Details, you can mail this string :)
            //mail example
            mailService.mailError(error) //just an example
            //if you want to show the error on the error page
            out << error
            //if you want to show any custom message
            out << "Error mailed, check Email"
     }
    
  2. In the GSP page views/error.gsp Replace "<g:renderException exception="${exception}"/>" Tag with "<myTagLib:reportError><g:renderException exception="${exception}"/></myTagLib:reportError>"

ALL DONE... :)

Now what is happening is, whenever an exception occours(Even in AJAX Calls) the request is redirected to the error page, there we can capture all errors.

The Only place where this setup will not work is in the case of executions which are not binded on the request, that is: JOBS.

In this method i was able to catch all unanticipated Exceptions :) ..

thats how i do, hope that Helps :)

Regards Kushal

like image 121
Kushal Likhi Avatar answered Oct 04 '22 10:10

Kushal Likhi