Hi there.
I'm trying to catch exceptions from GoogleSDK, and this is not very easy to make something clean.
Some propositions
Google_Service_Exception interface with hasReason, getErrorsFromDomain ..GooglePushWebHookUrlUnauthorized.Regards.
Please provide more information in the problem you're having and what you're trying to accomplish.
We have $exception->getErrors() which can be used for this purpose.
Hi @bshaffer
You right, getErrors is available. But it simply return an array of un-typed array.
Right now,
I have a dedicated GoogleErrorsDecoder that is constructed with the result of Google_Service_Exception::getErrors.
An helper function hasError allow me to easily check the kind of error that is throw from GoogleAPI.
What I'm trying to say.
I can't use the try/catch with the exception matching system.
try {
$this->subscribeToPushNotification($memberId);
}
catch (\Google_Service_Exception $e) {
$errors = $e->getErrors();
$webHookUrlUnauthorized = false;
foreach($errors as $error) {
if(isset($error["reason"]) && $error["reason"] === "push.webhookUrlUnauthorized") {
$webHookUrlUnauthorized = true;
}
}
if(!$webHookUrlUnauthorized) {
throw $e;
}
}
The above example is very complex to read..
try {
$this->subscribeToPushNotification($memberId);
}
catch (\Google_WebHook_Url_Unauthorized $e) {
}
The above is very simple to read..
Regards.
Creating an exception class for every possible error is not really something we want to implement. However, having a method for getReason that returns the first error's reason might be a convenient way to handle this.
Thank you for your feature request. This client library is currently in maintenance mode. We are fixing necessary bugs and adding essential features to ensure this library continues to meet your needs for accessing Google APIs. After careful consideration, we have decided not to proceed with this enhancement. If you disagree, please feel free to re-open this issue and explain why you believe it is essential for users of this client library.
Most helpful comment
Hi @bshaffer
You right,
getErrorsis available. But it simply return an array of un-typed array.Right now,
I have a dedicated
GoogleErrorsDecoderthat is constructed with the result ofGoogle_Service_Exception::getErrors.An helper function
hasErrorallow me to easily check the kind of error that is throw from GoogleAPI.What I'm trying to say.
I can't use the try/catch with the exception matching system.
The above example is very complex to read..
The above is very simple to read..
Regards.