@@ -81,6 +81,29 @@ async def _get_with_auth(self, client: httpx.AsyncClient, url: str) -> Dict:
8181 headers = {"Authorization" : f"Bearer { access_token } " }
8282 response = await client .get (url , headers = headers )
8383
84+ # Log detailed error information for 4xx/5xx responses before raising
85+ if not response .is_success :
86+ try :
87+ error_body = response .json ()
88+ correlation_id = error_body .get ("correlationId" , "N/A" )
89+ error_message = error_body .get ("message" , "No message provided" )
90+ error_category = error_body .get ("category" , "Unknown" )
91+ self .logger .error (
92+ f"❌ HubSpot API error at { url } - "
93+ f"Status: { response .status_code } , "
94+ f"Message: { error_message } , "
95+ f"Category: { error_category } , "
96+ f"CorrelationId: { correlation_id } , "
97+ f"Full response: { error_body } "
98+ )
99+ except Exception :
100+ # If we can't parse JSON, log the raw response
101+ self .logger .error (
102+ f"❌ HubSpot API error at { url } - "
103+ f"Status: { response .status_code } , "
104+ f"Response: { response .text } "
105+ )
106+
84107 response .raise_for_status ()
85108 return response .json ()
86109
@@ -124,6 +147,31 @@ async def _post_with_auth(
124147 }
125148 response = await client .post (url , headers = headers , json = json_data )
126149
150+ # Log detailed error information for 4xx/5xx responses before raising
151+ if not response .is_success :
152+ try :
153+ error_body = response .json ()
154+ correlation_id = error_body .get ("correlationId" , "N/A" )
155+ error_message = error_body .get ("message" , "No message provided" )
156+ error_category = error_body .get ("category" , "Unknown" )
157+ self .logger .error (
158+ f"❌ HubSpot API error at { url } - "
159+ f"Status: { response .status_code } , "
160+ f"Message: { error_message } , "
161+ f"Category: { error_category } , "
162+ f"CorrelationId: { correlation_id } , "
163+ f"Request body: { json_data } , "
164+ f"Full response: { error_body } "
165+ )
166+ except Exception :
167+ # If we can't parse JSON, log the raw response
168+ self .logger .error (
169+ f"❌ HubSpot API error at { url } - "
170+ f"Status: { response .status_code } , "
171+ f"Request body: { json_data } , "
172+ f"Response: { response .text } "
173+ )
174+
127175 response .raise_for_status ()
128176 return response .json ()
129177
0 commit comments