TDL-13763: Properly handle 4xx responses for adCampaignGroup stream#28
Conversation
| }, | ||
| 403: { | ||
| "raise_exception": LinkedInForbiddenError, | ||
| "message": "User doesn't have permission to access the resource." |
There was a problem hiding this comment.
@harshpatel4crest Update the message to "User does not have permission to access the resource."
| 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): |
…into TDL-13763-handle-4xx-error-in-adCampaignGroup
…://github.com/singer-io/tap-linkedin-ads into TDL-13763-handle-4xx-error-in-adCampaignGroup
| pass | ||
|
|
||
| class LinkedInForbiddenError(LinkedInError): | ||
| class LinkedInRateLimitExceeeded(Server429Error): |
There was a problem hiding this comment.
Can we put an Error postfix?
| class LinkedInForbiddenError(LinkedInError): | ||
| pass | ||
|
|
||
| class LinkedInLengthRequired(LinkedInError): |
There was a problem hiding this comment.
Can we put an Error postfix?
|
|
||
|
|
||
| class LinkedInPaymentRequiredError(LinkedInError): | ||
| class LinkedInMethodNotAllowed(LinkedInError): |
There was a problem hiding this comment.
Can we put an Error postfix?
| except Exception: | ||
| response_json = {} | ||
|
|
||
| if error_code == 404: |
There was a problem hiding this comment.
If the message is static and we also updating that then do we need to use mapping for 404?
| 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.
Handle this scenario before else condition.
There was a problem hiding this comment.
It will handle here only because we are appending the message at the end of response message/custom message.
| response_json = {} | ||
|
|
||
| if error_code == 404: | ||
| error_description = "The resource you have specified cannot be found." |
There was a problem hiding this comment.
@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) |
There was a problem hiding this comment.
@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) |
There was a problem hiding this comment.
@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"): |
There was a problem hiding this comment.
@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")))
KAllan357
left a comment
There was a problem hiding this comment.
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