facebook / facebook-php-business-sdk

PHP SDK for Meta Marketing API
https://developers.facebook.com/docs/business-sdk
Other
837 stars 519 forks source link

Do not throw an exception on existing field access not returned by the api #130

Closed yamsellem closed 9 years ago

yamsellem commented 9 years ago

Accessing to a field can throw exception like "actions is not a field of FacebookAds\\Object\\Insights".

This is wrong: actions is a field of Insights, it's accessible for several objects, but, when the field is not returned by facebook api, the sdk throw this exception.

The issue is in AbstractObject. The presence of the field in the enum should be asserted if the api result is null before throwing an exception.

And this leads to ugly catch in client code:

try {
  $actions = $entity->{InsightsFields::ACTIONS};
} catch(\InvalidArgumentException $e) {
  $actions = null;
};
chicag0 commented 9 years ago

Thanks, I tested this and it solved an issue I was having.

pruno commented 9 years ago

Fixed by https://github.com/facebook/facebook-php-ads-sdk/commit/134eca31ad46821f7d12efc743a87b4900296de9