Better handle responses missing expected keys

This commit is contained in:
Deon George 2024-07-14 13:46:04 +10:00
parent 403d2168c1
commit 947e1358b5

View File

@ -198,7 +198,7 @@ final class API
$x = $this->execute('query',$parameters); $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)); throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY));
return new Customer($x->QueryResponse); return new Customer($x->QueryResponse);
@ -251,8 +251,8 @@ final class API
$x = $this->execute('query',$parameters); $x = $this->execute('query',$parameters);
if ((! $x->QueryResponse) || (! $x->QueryResponse->Invoice) || (count($x->QueryResponse->Invoice) !== 1)) if ((! $x->QueryResponse) || (! object_get($x->QueryResponse,'Invoice')) || (count($x->QueryResponse->Invoice) !== 1))
throw new InvalidQueryResultException(sprintf('%s:Query response malformed',self::LOGKEY)); throw new InvalidQueryResultException(sprintf('%s:Query response malformed [%s]',self::LOGKEY,serialize($x)));
return new Invoice($x->QueryResponse); return new Invoice($x->QueryResponse);
} }