From 947e1358b52270ff36bf87f4b4c60e9e54bf892d Mon Sep 17 00:00:00 2001 From: Deon George Date: Sun, 14 Jul 2024 13:46:04 +1000 Subject: [PATCH] Better handle responses missing expected keys --- src/API.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/API.php b/src/API.php index 1942a38..22063d2 100644 --- a/src/API.php +++ b/src/API.php @@ -198,7 +198,7 @@ final class API $x = $this->execute('query',$parameters); - if ((! $x->QueryResponse) || (! $x->QueryResponse->Customer) || (count($x->QueryResponse->Customer) !== 1)) + if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Customer')) || (count($x->QueryResponse->Customer) !== 1)) throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY)); return new Customer($x->QueryResponse); @@ -251,8 +251,8 @@ final class API $x = $this->execute('query',$parameters); - if ((! $x->QueryResponse) || (! $x->QueryResponse->Invoice) || (count($x->QueryResponse->Invoice) !== 1)) - throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY)); + if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Invoice')) || (count($x->QueryResponse->Invoice) !== 1)) + throw new InvalidQueryResultException(sprintf('%s:Query response malformed [%s]',self::LOGKEY,serialize($x))); return new Invoice($x->QueryResponse); }