Closed necrogami closed 2 years ago
Do you mean it logs the error when trying to create a new UserRefreshCredentials
in this line, right?
If so, that code is inside the google-auth-library-php
. Could you please file a bug there instead?
It is on that line, It exits, It doesn't log the error it doesn't throw a throwable error or exception it catches it internally and exits. And because of how it is caught internally i can't catch and handle to be able to tell customers that their token is invalid or expired.
Also i have a ticket open with that team as well and have received no response.
https://github.com/googleapis/google-auth-library-php/issues/404
Could you please try pinging the issue agin? I'm afraid I cannot do anything much here, as it's outside this repository.
@fiboknacky now they are telling me that this needs to be handled as a middleware in google ads api library? Each side is pointing fingers at the other.
After closely looking into this, it looks like the exception isn't printed out as a log directly.
The message
part of ClientException
may confuse us, since it beautifully prints out the error message in a JSON format.
However, it's still thrown as a normal exception. That means you can do something like this:
try {
// Generate a refreshable OAuth2 credential for authentication.
$oAuth2Credential = (new OAuth2TokenBuilder())
->withClientId(env('GOOGLE_ADS_CLIENT_ID'))
->withClientSecret(env('GOOGLE_ADS_CLIENT_SECRET'))
->withRefreshToken($refreshToken)
->build();
} catch (ClientException $e) {
// Do something with $e.
}
Could you give it a try?
Except it's not, if you notice my code above, I'm catching \Throwable which is under \Error or \Exception the root of all throwable errors in php and it's still not being caught, this is because something upstream is catching the error before it comes to the client.
I just tried yesterday and it worked perfectly. I don't think we have any layers that would catch ClientException
.
Do you mean it still doesn't work even if you specify an \Exception
or ClientException
like I mentioned?
If you look at the code in the first post, it should just fail silently, It doesn't matter if i catch ClientException
which extends Exception
Which extends Throwable
It doesn't matter which i try and catch, none catch the above refresh token error nor any authentication based error. Of which were currently seeing 3.
If you look at the code in the first post, it should just fail silently, It doesn't matter if i catch ClientException which extends Exception Which extends Throwable none catch the above refresh token error nor any authentication based error.
That's the part I don't understand because as I mentioned in my previous reply, I just tried the solution I shared above and it successfully catches the exact exception you mentioned in the first post. And in the error message itself, it says that it is of the GuzzleHttp\Exception\ClientException
type, so there is no reason that catch
will not work on ClientException
.
Correct me if I'm wrong. You're trying to catch this exception and do something with it, right? If it fails silently even if you try to catch like I showed, that may be because of other reasons, which we need to figure out further. But for the basic PHP settings, it should work.
Thats just it, it's not failing silently, it's being caught earlier upstream. Even though i want to do something with it it's already caught, and handled and dumped out and exited the code. I'm currently running this in a laravel job queue, this exits the queue worker completely and dumping the error output out as listed above. I'm not asking it to, it just is.
I see. I think the best way to test would be modifying one of our code examples to include catching of ClientException
. (That's what I test in this reply) Could you please try that too?
And would it be possible to test using grpc
instead of rest
?
I know that the code in your original post is similar to our code examples, but let's make it more aligned to remove unrelated factors.
Closing due to inactivity. Feel free to reopen this if you still face the issue.
Your client library and Google Ads API versions:
v15.0
10
Your environment:
rest
Description of the bug: We have a need to be able to catch, and handle when a refresh token comes back as invalid or expired. We need to be able to send a message off to our customers to refresh their tokens. Currently i'm not seeing a way to handle this within the initiator.
Steps to reproduce:
with the code above passing in an invalid or expired token causes guzzle to throw this error into logs, it's not catchable even with catching
\Throwable
Expected behavior: A catchable exception that we can handle Request/Response Logs:
Anything else we should know about your project / environment: