Title: [PATCH] Make sure new error email functionality catches exceptions
Last modified: August 20, 2016

---

# [PATCH] Make sure new error email functionality catches exceptions

 *  Resolved [gmcinnes](https://wordpress.org/support/users/gmcinnes/)
 * (@gmcinnes)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/patch-make-sure-new-error-email-functionality-catches-exceptions/)
 * As written in 2.1.1 the error email functionality will only catch SalesForce 
   API errors that are returned cleanly via the SF API. Unfortunately, the SOAP 
   API can raise Exceptions such as type errors. I’ve created a patch to catch those
   Exceptions and report them using the same Debug and Mail functionality as already
   implemented.
 * Unfortunately this will only apply cleanly after already applying the patch here:
 * [http://wordpress.org/support/topic/cleaning-utf-8-for-soap-submission?replies=3](http://wordpress.org/support/topic/cleaning-utf-8-for-soap-submission?replies=3)
 *     ```
       --- salesforce-api.php	2012-11-27 16:41:10.000000000 -0500
       +++ salesforce-api.php.exceptions	2012-11-29 19:55:58.000000000 -0500
       @@ -1431,8 +1431,23 @@
                // Object type
                $account->type = $feed['meta']['contact_object_name'];
   
       +  // Some calls to the SalesForce API can result in exceptions being thrown
       +  // We need to catch them here so that we can report on them as effectively
       +  // As we report on other types of errors
       +	$api_exception = "";
       +	try
       +	{
                $result = $api->create(array($account));
       -
       +	}
       +	catch (Exception $e)
       +	{
       +		$api_exception = "Message: "  . $e->getMessage() .
       +                                 "\nFaultstring: " . $e->faultstring .
       +                                 "\nFile: " . $e->getFile() .
       +                                 "\nLine: " . $e->getLine() .
       +				                         "\nArgs: ". serialize($merge_vars) .
       +                                 "\nTrace: " . serialize($e->getTrace());
       +	}
                $debug = '';
                if(self::is_debug()) {
                    $debug = '<pre>'.print_r(array(
       @@ -1442,7 +1457,8 @@
                            'Salesforce Posted Merge Data' => $merge_vars,
                            'Posted Data ($_POST)' => $_POST,
                            'result' => $result[0],
       -                    '$api' => $api
       +                    '$api' => $api,
       +                    '$api_exception' => $api_exception
                        ), true).'</pre>';
                }
   
       @@ -1465,8 +1481,8 @@
                        $headers = "Content-type: text/html; charset=" . get_option('blog_charset') . "\r\n";
                        wp_mail($email,__('Error adding to Salesforce', 'gravity-forms-salesforce'), $message, $headers);
                    }
       +            self::add_note($entry["id"], sprintf(__('Errors when adding to Salesforce: %s', 'gravity-forms-salesforce'), $errors->message . $api_exception));
   
       -            self::add_note($entry["id"], sprintf(__('Errors when adding to Salesforce: %s', 'gravity-forms-salesforce'), $errors->message));
   
                    return false;
                }
       ```
   
 * [http://wordpress.org/extend/plugins/gravity-forms-salesforce/](http://wordpress.org/extend/plugins/gravity-forms-salesforce/)

Viewing 1 replies (of 1 total)

 *  Plugin Contributor [Zack Katz](https://wordpress.org/support/users/katzwebdesign/)
 * (@katzwebdesign)
 * [13 years, 6 months ago](https://wordpress.org/support/topic/patch-make-sure-new-error-email-functionality-catches-exceptions/#post-3230704)
 * Thanks! This will be added to the next version.

Viewing 1 replies (of 1 total)

The topic ‘[PATCH] Make sure new error email functionality catches exceptions’ is
closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/gravity-forms-salesforce_fbfdff.svg)
 * [Gravity Forms Salesforce Add-on](https://wordpress.org/plugins/gravity-forms-salesforce/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/gravity-forms-salesforce/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/gravity-forms-salesforce/)
 * [Active Topics](https://wordpress.org/support/plugin/gravity-forms-salesforce/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/gravity-forms-salesforce/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/gravity-forms-salesforce/reviews/)

 * 1 reply
 * 2 participants
 * Last reply from: [Zack Katz](https://wordpress.org/support/users/katzwebdesign/)
 * Last activity: [13 years, 6 months ago](https://wordpress.org/support/topic/patch-make-sure-new-error-email-functionality-catches-exceptions/#post-3230704)
 * Status: resolved