From 19df1912975c0c04ffd13cdb42c5419f48542b2d Mon Sep 17 00:00:00 2001 From: Chris Brown Date: Sun, 21 Jun 2020 19:02:46 -0400 Subject: [PATCH] Catch empty error condition (rare, but could occur if connection to Square times out) --- .../includes/modules/payment/square.php | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/files_to_upload/includes/modules/payment/square.php b/files_to_upload/includes/modules/payment/square.php index 9eeb0b7..1bcc42d 100644 --- a/files_to_upload/includes/modules/payment/square.php +++ b/files_to_upload/includes/modules/payment/square.php @@ -1264,13 +1264,15 @@ protected function parse_error_response($error_object) $msg = ''; $first_category = null; $first_code = null; - foreach ($error_object as $err) { - $category = method_exists($err, 'getCategory') ? $err->getCategory() : $err->category; - $code = method_exists($err, 'getCode') ? $err->getCode() : $err->code; - $detail = method_exists($err, 'getDetail') ? $err->getDetail() : $err->detail; - $msg .= "$code: $detail\n"; - if (is_null($first_category)) $first_category = $category; - if (is_null($first_code)) $first_code = $code; + if (!empty($error_object)) { + foreach ($error_object as $err) { + $category = method_exists($err, 'getCategory') ? $err->getCategory() : $err->category; + $code = method_exists($err, 'getCode') ? $err->getCode() : $err->code; + $detail = method_exists($err, 'getDetail') ? $err->getDetail() : $err->detail; + $msg .= "$code: $detail\n"; + if (is_null($first_category)) $first_category = $category; + if (is_null($first_code)) $first_code = $code; + } } $msg = trim($msg, "\n"); $msg = str_replace("\n", "\n
", $msg); @@ -1279,7 +1281,6 @@ protected function parse_error_response($error_object) return array('detail' => $msg, 'category' => $first_category, 'code' => $first_code); } - } // helper for Square admin configuration: locations selector