From 8e51c69a51b341939292b4549b1812dc0848e2de Mon Sep 17 00:00:00 2001 From: Matt Drayer Date: Tue, 10 Oct 2017 16:40:13 -0400 Subject: [PATCH] Log additional context for SuccessFactors errors. --- common/djangoapps/third_party_auth/saml.py | 20 +++++++++++-------- .../tests/specs/test_testshib.py | 5 +++-- 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/common/djangoapps/third_party_auth/saml.py b/common/djangoapps/third_party_auth/saml.py index b70b17b92e..df3c45a71f 100644 --- a/common/djangoapps/third_party_auth/saml.py +++ b/common/djangoapps/third_party_auth/saml.py @@ -307,15 +307,19 @@ class SapSuccessFactorsIdentityProvider(EdXSAMLIdentityProvider): response = response.json() except requests.RequestException as err: # If there was an HTTP level error, log the error and return the details from the SAML assertion. - log.warning( - 'Unable to retrieve user details with username %s from SAPSuccessFactors for company ID %s ' - 'with url "%s" and error message: %s', - username, - self.odata_company_id, - odata_api_url, - err.message, - exc_info=True, + sys_msg = err.response.json() if err.response else "Not available" + log_msg_template = ( + 'Unable to retrieve user details with username {username} from SAPSuccessFactors for company ' + + 'ID {company} with url "{url}". Error message: {err_msg}. System message: {sys_msg}.' ) + log_msg = log_msg_template.format( + username=username, + company=self.odata_company_id, + url=odata_api_url, + err_msg=err.message, + sys_msg=sys_msg + ) + log.warning(log_msg, exc_info=True) return details return self.get_registration_fields(response) diff --git a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py index 5aa064e3c0..3ac2c3bb7d 100644 --- a/common/djangoapps/third_party_auth/tests/specs/test_testshib.py +++ b/common/djangoapps/third_party_auth/tests/specs/test_testshib.py @@ -517,8 +517,9 @@ class SuccessFactorsIntegrationTest(SamlIntegrationTestUtilities, IntegrationTes with LogCapture(level=logging.WARNING) as log_capture: super(SuccessFactorsIntegrationTest, self).test_register() expected_message = 'Unable to retrieve user details with username {username} from SAPSuccessFactors ' \ - 'for company ID {company_id} with url "{odata_api_url}" and error message: ' \ - '500 Server Error: Internal Server Error for url: {odata_api_url}'.format( + 'for company ID {company_id} with url "{odata_api_url}". Error message: ' \ + '500 Server Error: Internal Server Error for url: {odata_api_url}. System message: ' \ + 'Not available.'.format( username=self.USER_USERNAME, company_id=odata_company_id, odata_api_url=mocked_odata_ai_url,