Fixed pulling of notes when API returns NULL
This commit is contained in:
@@ -74,6 +74,38 @@ namespace URLNotesGrabberCORE
|
||||
var response = APIAccess.GrabNotes(blogName, postID).GetAwaiter().GetResult();
|
||||
List<Tuple<string, string>> notes = new List<Tuple<string, string>>();
|
||||
|
||||
// Check for API errors
|
||||
if (response.statusCode == "NotFound")
|
||||
{
|
||||
Console.WriteLine($"ERROR: Post not found - {blogName}/{postID}");
|
||||
break;
|
||||
}
|
||||
if (response.statusCode == "TooManyRequests")
|
||||
{
|
||||
Console.WriteLine($"ERROR: Rate limited - retry in {response.retryInSeconds} seconds");
|
||||
break;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(response.statusCode))
|
||||
{
|
||||
Console.WriteLine($"ERROR: API returned status code: {response.statusCode}");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for null response
|
||||
if (response.response == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: API response is null");
|
||||
break;
|
||||
}
|
||||
|
||||
// Check for null notes
|
||||
if (response.response.notes == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: Notes collection is null (post may have 0 notes)");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Processing {response.response.notes.Count} notes...");
|
||||
foreach (var note in response.response.notes)
|
||||
{
|
||||
note.reblog_parent_blog_name = blogName; note.post_id = postID.ToString();
|
||||
@@ -86,6 +118,13 @@ namespace URLNotesGrabberCORE
|
||||
{
|
||||
response = APIAccess.GrabNotes(blogName, postID, response.response._links.next.query_params.before_timestamp).GetAwaiter().GetResult();
|
||||
|
||||
if (response.response?.notes == null)
|
||||
{
|
||||
Console.WriteLine("ERROR: Notes collection became null during pagination");
|
||||
break;
|
||||
}
|
||||
|
||||
Console.WriteLine($"Processing {response.response.notes.Count} more notes...");
|
||||
foreach (var note in response.response.notes)
|
||||
{
|
||||
note.reblog_parent_blog_name = blogName; note.post_id = postID.ToString(); ;
|
||||
@@ -94,6 +133,8 @@ namespace URLNotesGrabberCORE
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine("Test completed successfully");
|
||||
#endregion
|
||||
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user