-
Notifications
You must be signed in to change notification settings - Fork 22
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
TDL-13763: Properly handle 4xx responses for adCampaignGroup stream #28
TDL-13763: Properly handle 4xx responses for adCampaignGroup stream #28
Conversation
tap_linkedin_ads/client.py
Outdated
}, | ||
403: { | ||
"raise_exception": LinkedInForbiddenError, | ||
"message": "User doesn't have permission to access the resource." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshpatel4crest Update the message to "User does not have permission to access the resource."
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
except client.LinkedInLengthRequired as e: | ||
self.assertEquals(str(e), "HTTP-error-code: 411, Error: {}".format(response_json.get('message'))) | ||
|
||
# def test_500_error_response_message(self, mocked_access_token, mocked_request): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we remove this?
…into TDL-13763-handle-4xx-error-in-adCampaignGroup
…://github.com/singer-io/tap-linkedin-ads into TDL-13763-handle-4xx-error-in-adCampaignGroup
tap_linkedin_ads/client.py
Outdated
|
||
class LinkedInForbiddenError(LinkedInError): | ||
class LinkedInRateLimitExceeeded(Server429Error): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put an Error postfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tap_linkedin_ads/client.py
Outdated
pass | ||
|
||
class LinkedInLengthRequired(LinkedInError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put an Error postfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tap_linkedin_ads/client.py
Outdated
@@ -27,65 +26,99 @@ class LinkedInUnauthorizedError(LinkedInError): | |||
pass | |||
|
|||
|
|||
class LinkedInPaymentRequiredError(LinkedInError): | |||
class LinkedInMethodNotAllowed(LinkedInError): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we put an Error postfix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
except Exception: | ||
response_json = {} | ||
|
||
if error_code == 404: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the message is static and we also updating that then do we need to use mapping for 404?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
tap_linkedin_ads/client.py
Outdated
else: | ||
error_description = response_json.get("message", ERROR_CODE_EXCEPTION_MAPPING.get(error_code, {}).get("message", "Unknown Error") if response_json == {} else response_json) | ||
|
||
if error_code == 400: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Handle this scenario before else condition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It will handle here only because we are appending the message at the end of response message/custom message.
tap_linkedin_ads/client.py
Outdated
response_json = {} | ||
|
||
if error_code == 404: | ||
error_description = "The resource you have specified cannot be found." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshpatel4crest, Since this, if
condition is generic among all streams, please keep the error description in the 'ERROR_CODE_EXCEPTION_MAPPING ' only
tap_linkedin_ads/client.py
Outdated
error_description = "The resource you have specified cannot be found." | ||
error_description += " Please check the account numbers or you don't have access to the Ad Account." | ||
elif response_json.get("message") and "see errorDetails for more information" in response_json.get("message"): | ||
error_description = response_json.get("errorDetails").get("inputErrors", [{}])[0].get("code", None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshpatel4crest Please consider the complete information provided in error_description
tap_linkedin_ads/client.py
Outdated
error_description = str(response_json.get("errorDetails")) | ||
else: | ||
# get message from the reponse if present or get custom message if not present | ||
error_description = response_json.get("message", ERROR_CODE_EXCEPTION_MAPPING.get(error_code, {}).get("message", "Unknown Error") if response_json == {} else response_json) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshpatel4crest Please optimize this condition
tap_linkedin_ads/client.py
Outdated
if error_code == 404: | ||
# 404 returns "Not Found" so getting custom message | ||
error_description = ERROR_CODE_EXCEPTION_MAPPING.get(error_code).get("message") | ||
elif response_json.get("errorDetails"): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@harshpatel4crest Code Optimization:
We can remove the elif condition by putting the below code in else condition
response_json.get("errorDetails", response_json.get("message", ERROR_CODE_EXCEPTION_MAPPING.get(error_code, {}).get("message", "Unknown Error")))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change seems to have lost support for error code 402 - is there a reason why that happened?
@KAllan357 We have followed the documentation for the error handling and we haven't found 402 in the (doc) so we removed it. |
Tests are failing here after merging master. |
Description of change
TDL-13763: Properly handle 4xx responses for adCampaignGroup stream
TDL-13764: Investigate JSON decoding error
Manual QA steps
Rollback steps