Skip to content
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

Merged
merged 17 commits into from
Aug 13, 2021

Conversation

hpatel41
Copy link
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

},
403: {
"raise_exception": LinkedInForbiddenError,
"message": "User doesn't have permission to access the resource."
Copy link
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
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
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?


class LinkedInForbiddenError(LinkedInError):
class LinkedInRateLimitExceeeded(Server429Error):
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Done

pass

class LinkedInLengthRequired(LinkedInError):
Copy link
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
Contributor Author

Choose a reason for hiding this comment

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

Done

@@ -27,65 +26,99 @@ class LinkedInUnauthorizedError(LinkedInError):
pass


class LinkedInPaymentRequiredError(LinkedInError):
class LinkedInMethodNotAllowed(LinkedInError):
Copy link
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
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
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
Contributor Author

Choose a reason for hiding this comment

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

Done

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
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
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
response_json = {}

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

@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

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)

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

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)

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

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

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

None yet

5 participants