From 47c1b85cf45e933d3eac00282962d6075cea8c47 Mon Sep 17 00:00:00 2001
From: Matthew Wire <mjw@mjwconsult.co.uk>
Date: Fri, 1 Jul 2022 22:56:00 +0100
Subject: [PATCH] Fix error message on AJAX 500 error

---
 js/civicrm_stripe.js | 25 ++++++++++++++-----------
 1 file changed, 14 insertions(+), 11 deletions(-)

diff --git a/js/civicrm_stripe.js b/js/civicrm_stripe.js
index 5f2a338b..22059402 100644
--- a/js/civicrm_stripe.js
+++ b/js/civicrm_stripe.js
@@ -307,18 +307,21 @@
      */
     stripePaymentIntentProcessFail: function(failObject) {
       var error = ts('Unknown error');
-      if (failObject.hasOwnProperty('error_message')) {
-        // From an API4 exception
-        error = failObject.error_message;
-      }
-      else if (failObject.hasOwnProperty('statusText') && (failObject.statusText !== 'OK')) {
-        // A PHP exit can return 200 "OK" but we don't want to display "OK" as the error!
-        if (failObject.statusText === 'parsererror') {
-          error = ts('Configuration error - unable to process paymentIntent');
-        }
-        else {
-          error = failObject.statusText;
+      if (typeof failObject !== 'undefined') {
+        if (failObject.hasOwnProperty('error_message')) {
+          // From an API4 exception
+          error = failObject.error_message;
         }
+        else
+          if (failObject.hasOwnProperty('statusText') && (failObject.statusText !== 'OK')) {
+            // A PHP exit can return 200 "OK" but we don't want to display "OK" as the error!
+            if (failObject.statusText === 'parsererror') {
+              error = ts('Configuration error - unable to process paymentIntent');
+            }
+            else {
+              error = failObject.statusText;
+            }
+          }
       }
       CRM.payment.displayError(error, true);
       script.reloadReCAPTCHA();
-- 
GitLab