How to get an Email Notification for every Exception

Magentos error handling is pretty good. PHP Errors, Warnings or Notices are written into the system.log file and Exceptions are caught by Magento to show the customer a (not very good looking) page and write the error stack into a file as a report for the system administrator.

Ok, but how often are those exceptions coming up? Sure - you tested your ecommerce store very well to prevent those situations for your customers, but you know - its software!

Even the best tested site is not 100% bug-free.
Some customers may contact you and report their error but the most wont. And you really want to fix any Exception that is thrown by your shop.

So here is the solution: We'll integrate an instant notification or a daily report for any exception that is occuring on your Magento webshop.

With the help of our module Notify for Magento, that is very easy.

The module is a notification system that also can create summaries of the collected data and send them as recurring reports.

To be able to configure a notification or report for a thrown exception, we only need to insert a little piece of code into the exception page:

// prepare data object
$data = Mage::getSingleton('notify/issue_data');
// trigger customer_experienced_exception

Put this on the end of the file /errors/default/report.phtml.

We have to setup this new trigger for Notify to be able to configure a notification or report in the admin panel.

Open your notify.xml of your custom module that extends Notify or of Grafzahl_Notify module (not recommended).

Add the configuration for our new trigger (config/notify/trigger - node):

<error label="Error">
    <customer_experienced_exception label="User gets an Exception">
            <error type="string">Error Message</error>
            <report_id type="string">Report Id</report_id>
            <backtrace type="string">Backtrace</backtrace>

Create the renderer class and you are done! The renderer class is only a simple class with extends the renderer abstract like the following:

 * Grafzahl_Notify
 * @category    Grafzahl
 * @package     Grafzahl_Notify
 * @copyright   Copyright (c) 2017 Grafzahl (https://grafzahl.io)
 * @license     https://grafzahl.io/license
class Grafzahl_Notify_Block_Renderer_Error_CustomerExperiencedException
    extends Grafzahl_Notify_Block_Renderer_Abstract


It is recommended to create those files in your custom module that is extending the default Notify module.

Configure the notification

Now you can configure the report or notification in the admin panel. Read about that in our documenation.

To get this powerful notification module for your Magento store, visit https://grafzahl.io/notify-module

No comments:

Post a Comment