From cdf1781f7770576a35ce95498e87aef1cd7da18d Mon Sep 17 00:00:00 2001 From: R Ryan Dial Date: Mon, 9 Sep 2024 14:36:16 -0400 Subject: [PATCH 1/2] EP-7911 :: don't raise exceptions and do provide more context --- src/Organic/SDK/OrganicSdk.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/Organic/SDK/OrganicSdk.php b/src/Organic/SDK/OrganicSdk.php index eec1ec6..f73951c 100644 --- a/src/Organic/SDK/OrganicSdk.php +++ b/src/Organic/SDK/OrganicSdk.php @@ -560,7 +560,9 @@ private function runQuery( $query, array $variables = [] ) { return $result->getResults(); } catch ( QueryError $e ) { - throw new RuntimeException( 'Organic API Failed', -1, $e ); + // Variable is encoded this way so we get more context in Sentry + $query_error_details = json_encode( $e->getErrorDetails() ); + throw new RuntimeException( 'Organic API Failed with ' . count( json_decode( $query_error_details ) . ' errors'), -1, $e ); } } @@ -587,16 +589,15 @@ public function updateToken( $token ) { * * @param $array * @param $dataType - * @throws InvalidArgumentException if a required value is missing + * @return object[] */ - private function metaArrayToObjects( $array, $dataType ) { + private function metaArrayToObjects( $array, $dataType ): array { $objects = []; foreach ( $array as $value ) { - if ( ! isset( $value['externalId'] ) || ! isset( $value['name'] ) ) { - throw new InvalidArgumentException( - 'Missing externalId or name attribute in ' . $dataType - ); + $value['name'] = $value['name'] ?? $value['email'] ?? '(not set)'; + if ( ! isset( $value['externalId'] ) ) { + continue; } $objects[] = $value; } From 08db5f952e41341a841ec6ec9385ebe88de75727 Mon Sep 17 00:00:00 2001 From: R Ryan Dial Date: Tue, 10 Sep 2024 10:33:04 -0400 Subject: [PATCH 2/2] codestyle --- src/Organic/SDK/OrganicSdk.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Organic/SDK/OrganicSdk.php b/src/Organic/SDK/OrganicSdk.php index f73951c..7972939 100644 --- a/src/Organic/SDK/OrganicSdk.php +++ b/src/Organic/SDK/OrganicSdk.php @@ -562,7 +562,7 @@ private function runQuery( $query, array $variables = [] ) { } catch ( QueryError $e ) { // Variable is encoded this way so we get more context in Sentry $query_error_details = json_encode( $e->getErrorDetails() ); - throw new RuntimeException( 'Organic API Failed with ' . count( json_decode( $query_error_details ) . ' errors'), -1, $e ); + throw new RuntimeException( 'Organic API Failed with ' . count( json_decode( $query_error_details ) . ' errors' ), -1, $e ); } }