Skip to content
This repository has been archived by the owner on Mar 12, 2024. It is now read-only.

Commit

Permalink
Catch empty error condition
Browse files Browse the repository at this point in the history
(rare, but could occur if connection to Square times out)
  • Loading branch information
drbyte committed Jun 21, 2020
1 parent 0eae6f5 commit 19df191
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions files_to_upload/includes/modules/payment/square.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<br>", $msg);
Expand All @@ -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
Expand Down

0 comments on commit 19df191

Please sign in to comment.