-
Notifications
You must be signed in to change notification settings - Fork 473
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do you compare ErrorCode
s?
#83
Comments
I expected to be able to at least used the An example: In [432]: exception.failure.errors[0].error_code
Out[432]: authentication_error: CUSTOMER_NOT_FOUND
In [433]: authentication_error = client.get_type('AuthenticationErrorEnum', version='v1')
In [434]: authentication_error.CUSTOMER_NOT_FOUND
Out[434]: 8
In [435]: exception.failure.errors[0].error_code == authentication_error.CUSTOMER_NOT_FOUND
Out[435]: False |
Hi @wesleybowman It looks like you're on the right track for finding the values you're trying to compare. |
@BenRKarl I actually made the query crash so that I could try and compare different errors. We have customers that will get these different errors, and I want to send them down different code paths depending on which error they get. I think using a |
@wesleybowman This is horrendous, but here is how i'm doing it. Working in a python lib that has no built in interfaces or structure and instead by hidden proto files, is extremely difficult. It's been a long time since i couldn't get a single thing off of intellisense. But here is my crappy way.
|
Agreed. It's been a difficult ride. What we ended up going with for now is the following: client = get_google_ads_client()
authentication_error_enum = client.get_type('AuthenticationErrorEnum', version='v1')
authorization_error_enum = client.get_type('AuthorizationErrorEnum', version='v1')
request_error_enum = client.get_type('RequestErrorEnum', version='v1')
for error in exception.failure.errors:
error_code = error.error_code
if error_code.authentication_error == authentication_error_enum.CUSTOMER_NOT_FOUND:
raise AdwordsPermissionError('Customer Not Found', exception)
elif error_code.authorization_error == authorization_error_enum.USER_PERMISSION_DENIED:
raise AdwordsPermissionError('User Permission Denied', exception)
elif error_code.request_error == request_error_enum.INVALID_CUSTOMER_ID:
raise AdwordsInvalidClientCustomerId('Invalid Client Customer ID', exception) Overall, fairly simple, but I am hoping there will be a better way in the future |
Awesome, thanks for the reply tip!
…On Wed, May 1, 2019 at 11:41 PM Wesley Bowman ***@***.***> wrote:
@j-walker23 <https://github.com/j-walker23>
It's been a long time since i couldn't get a single thing off of
intellisense.
Pretty miserable.
Agreed. It's been a difficult ride. What we ended up going with for now is
the following:
client = get_google_ads_client()
authentication_error_enum = client.get_type('AuthenticationErrorEnum', version='v1')
authorization_error_enum = client.get_type('AuthorizationErrorEnum', version='v1')
request_error_enum = client.get_type('RequestErrorEnum', version='v1')
for error in exception.failure.errors:
error_code = error.error_code
if error_code.authentication_error == authentication_error_enum.CUSTOMER_NOT_FOUND:
raise AdwordsPermissionError('Customer Not Found', exception)
elif error_code.authorization_error == authorization_error_enum.USER_PERMISSION_DENIED:
raise AdwordsPermissionError('User Permission Denied', exception)
elif error_code.request_error == request_error_enum.INVALID_CUSTOMER_ID:
raise AdwordsInvalidClientCustomerId('Invalid Client Customer ID', exception)
Overall, fairly simple, but I am hoping there will be a better way in the
future
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#83 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAPM4RPEYBY6KIYPVOVLDVLPTJ5IFANCNFSM4HGSNKNQ>
.
|
@j-walker23 @wesleybowman Thanks for coordinating with each other, and sorry for my delayed response. Is it accurate to describe the issue you're having generally as wanting to lookup the string name of an Enum field using the integer value pulled from a request object? It looks like that's the core problem - if not, or if I'm leaving off other problems, please add on here. The issue of doing this type of look up is definitely a major pain point. It's possible to do this a bit more easily by using the protobuf helpers, like this: from google.protouf.json_format import MessageToDict
# e is GoogleAdsException
failure = e.failure
dict = MessageToDict(failure)
for error in dict['errors']:
error_code = error['errorCode']
if error_code['authenticationError'] == 'CUSTOMER_NOT_FOUND':
raise AdwordsPermissionError('Customer Not Found', exception)
if error_code['authorizationError'] == 'USER_PERMISSION_DENIED':
raise AdwordsPermissionError('User Permission Denied', exception)
if error_code['requestError'] == 'INVALID_CUSTOMER_ID':
raise AdwordsInvalidClientCustomerId('Invalid Client Customer ID', exception) Admittedly it's not a whole lot better, but at least you don't need to deal with the Enum protos directly. One caveat about this solution is that it will generate errors if you are retrieving resource fields that contain a digit following an underscore, for example: I'm hoping to get functionality added to this library that will more easily expose the Enum field names so external helpers like Let me know if you have any additional questions or thoughts here. |
This would be wonderful!
No worries! We know you guys are busy. Keep up the good work 👍
I would like to extend this to also include an easier way to convert the campaign_status_enum = client.get_type('CampaignStatusEnum', version='v1').CampaignStatus.Name
for row in results:
status: str = campaign_status_enum.CampaignStatus.Name(row.campaign.status) IMHO, it would be nice if |
@wesleybowman Thank you for the explanation! I'm working on determining if there's a way that we can improve the interface for this. To be honest it won't be an easy change, so it might take some time. I'm going to close this issue since it's not directly related, but I'll open a new one to track progress against making Enums easier to work with. |
If I have the following:
There is a lot of information in
ex
. The examples in this repo print the exceptionrequest_id
and the name of the status (ex.error.code().name
)Instead of accessing the status, which can be general, I want to access the actual failures,
ex.failure.errors
.A use-case I have is that I want to trigger a certain code path if we receive a
CLIENT_CUSTOMER_ID_INVALID
and a different one if we get aCUSTOMER_NOT_ACTIVE
. Using theStatusCode
, both of these errors have a status ofUNAUTHENTICATED
.My thoughts are that you need to create your own
ErrorCode
, but I am not having success with that usingAny ideas?
The text was updated successfully, but these errors were encountered: