Skip to content

TDL-13763: Properly handle 4xx responses for adCampaignGroup stream#28

Merged
KAllan357 merged 17 commits into
masterfrom
TDL-13763-handle-4xx-error-in-adCampaignGroup
Aug 13, 2021
Merged

TDL-13763: Properly handle 4xx responses for adCampaignGroup stream#28
KAllan357 merged 17 commits into
masterfrom
TDL-13763-handle-4xx-error-in-adCampaignGroup

Conversation

@hpatel41
Copy link
Copy Markdown
Contributor

@hpatel41 hpatel41 commented Jun 29, 2021

Description of change

TDL-13763: Properly handle 4xx responses for adCampaignGroup stream
TDL-13764: Investigate JSON decoding error

  • Exception handling is updated with proper custom messages as part of TDL-13763 which will also handle JSON decoding errors.

Manual QA steps

  • Verified that exception is raised with custom error message as per API error code for JSON decoding error.

Rollback steps

  • revert this branch

Comment thread tap_linkedin_ads/client.py Outdated
},
403: {
"raise_exception": LinkedInForbiddenError,
"message": "User doesn't have permission to access the resource."
Copy link
Copy Markdown
Contributor

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."

Copy link
Copy Markdown
Contributor Author

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):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we remove this?

Comment thread tap_linkedin_ads/client.py Outdated
pass

class LinkedInForbiddenError(LinkedInError):
class LinkedInRateLimitExceeeded(Server429Error):
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread tap_linkedin_ads/client.py Outdated
class LinkedInForbiddenError(LinkedInError):
pass

class LinkedInLengthRequired(LinkedInError):
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread tap_linkedin_ads/client.py Outdated


class LinkedInPaymentRequiredError(LinkedInError):
class LinkedInMethodNotAllowed(LinkedInError):
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

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:
Copy link
Copy Markdown
Contributor

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread 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:
Copy link
Copy Markdown
Contributor

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.

Copy link
Copy Markdown
Contributor Author

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.

@hpatel41 hpatel41 requested a review from dbshah1212 July 9, 2021 10:36
Comment thread tap_linkedin_ads/client.py Outdated
response_json = {}

if error_code == 404:
error_description = "The resource you have specified cannot be found."
Copy link
Copy Markdown

@karanpanchal-crest karanpanchal-crest Jul 19, 2021

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

Comment thread 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)
Copy link
Copy Markdown

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

Comment thread 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)
Copy link
Copy Markdown

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

Comment thread 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"):
Copy link
Copy Markdown

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")))

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
Copy Markdown
Contributor

@KAllan357 KAllan357 left a 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?

@hpatel41
Copy link
Copy Markdown
Contributor Author

hpatel41 commented Aug 12, 2021

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.
Let us know if you want to continue adding support for 402.

@KAllan357
Copy link
Copy Markdown
Contributor

Tests are failing here after merging master.

@KAllan357 KAllan357 merged commit 0f91c27 into master Aug 13, 2021
@KAllan357 KAllan357 deleted the TDL-13763-handle-4xx-error-in-adCampaignGroup branch August 13, 2021 14:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants