Adding missed response body logging and API rate limiting

This commit is contained in:
= 2025-12-15 12:16:30 -05:00
parent 0dccb0ca9c
commit d304c1bb6a

View File

@ -391,6 +391,7 @@ public class APIHelper : IAPIHelper
response.EnsureSuccessStatusCode(); response.EnsureSuccessStatusCode();
var body = await response.Content.ReadAsStringAsync(); var body = await response.Content.ReadAsStringAsync();
WriteRawBody($"user-{endpoint.Replace("/", "_")}", body);
user = JsonConvert.DeserializeObject<Entities.User>(body, m_JsonSerializerSettings); user = JsonConvert.DeserializeObject<Entities.User>(body, m_JsonSerializerSettings);
return user; return user;
} }
@ -812,7 +813,7 @@ public class APIHelper : IAPIHelper
highlight_request.Headers.Add(keyValuePair.Key, keyValuePair.Value); highlight_request.Headers.Add(keyValuePair.Key, keyValuePair.Value);
} }
await EnforceApiRateLimitAsync(CurrentDiagnosticLogger); await EnforceApiRateLimitAsync(CurrentDiagnosticLogger, highlight_request.RequestUri?.ToString());
using var highlightResponse = await highlight_client.SendAsync(highlight_request); using var highlightResponse = await highlight_client.SendAsync(highlight_request);
highlightResponse.EnsureSuccessStatusCode(); highlightResponse.EnsureSuccessStatusCode();
var highlightBody = await highlightResponse.Content.ReadAsStringAsync(); var highlightBody = await highlightResponse.Content.ReadAsStringAsync();
@ -2237,7 +2238,8 @@ public class APIHelper : IAPIHelper
{ "skip_users", "all" } { "skip_users", "all" }
}; };
var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config)); var body = await BuildHeaderAndExecuteRequests(getParams, endpoint, GetHttpClient(config), CurrentDiagnosticLogger, "posts-paid-all-initial");
WriteRawBody("posts-paid-all-initial", body);
purchased = JsonConvert.DeserializeObject<Purchased>(body, m_JsonSerializerSettings); purchased = JsonConvert.DeserializeObject<Purchased>(body, m_JsonSerializerSettings);
if (purchased != null && purchased.hasMore) if (purchased != null && purchased.hasMore)
{ {
@ -2255,12 +2257,13 @@ public class APIHelper : IAPIHelper
{ {
looprequest.Headers.Add(keyValuePair.Key, keyValuePair.Value); looprequest.Headers.Add(keyValuePair.Key, keyValuePair.Value);
} }
await EnforceApiRateLimitAsync(CurrentDiagnosticLogger); await EnforceApiRateLimitAsync(CurrentDiagnosticLogger, looprequest.RequestUri?.ToString());
using (var loopresponse = await loopclient.SendAsync(looprequest)) using (var loopresponse = await loopclient.SendAsync(looprequest))
{ {
loopresponse.EnsureSuccessStatusCode(); loopresponse.EnsureSuccessStatusCode();
var loopbody = await loopresponse.Content.ReadAsStringAsync(); var loopbody = await loopresponse.Content.ReadAsStringAsync();
newPurchased = JsonConvert.DeserializeObject<Purchased>(loopbody, m_JsonSerializerSettings); newPurchased = JsonConvert.DeserializeObject<Purchased>(loopbody, m_JsonSerializerSettings);
WriteRawBody($"posts-paid-all-page-{getParams["offset"]}", loopbody);
} }
purchased.list.AddRange(newPurchased.list); purchased.list.AddRange(newPurchased.list);
if (!newPurchased.hasMore) if (!newPurchased.hasMore)