Skip to content

Commit

Permalink
make metadata read more reliable
Browse files Browse the repository at this point in the history
  • Loading branch information
elasticroentgen committed Aug 26, 2024
1 parent fc162d4 commit d001eac
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions HackMdApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,17 +192,26 @@ public async Task GetAllNotes()
var request = CreateRequest($"/api/notes?page={page}");
var response = await _client.SendAsync(request);
response.EnsureSuccessStatusCode();

string responseBody = await response.Content.ReadAsStringAsync();
NotesResponse notes = JsonSerializer.Deserialize <NotesResponse>(responseBody)!;

if (notes.result.Count == 0)
string responseBody = string.Empty;
NotesResponse notes = null;
try
{
responseBody = await response.Content.ReadAsStringAsync();
notes = JsonSerializer.Deserialize<NotesResponse>(responseBody)!;
}
catch (Exception ex)
{
Console.WriteLine($"Error during list fetch: {ex.Message} == {responseBody}");
}

if (notes is { result.Count: 0 })
{
// No more notes
returnedNotes = false;
Console.WriteLine("Got all note metadata.");
}
else
else if (notes != null)
{
allNotes.AddRange(notes.result);
Console.WriteLine($"Page {page}: Got {notes.result.Count} - Total {allNotes.Count}");
Expand Down

0 comments on commit d001eac

Please sign in to comment.