Skip to content

Commit

Permalink
fix: nullpointer if a product doesn't have a picture in grocy. (#7)
Browse files Browse the repository at this point in the history
  • Loading branch information
GoodOldJack12 authored Feb 28, 2024
1 parent 54f471b commit caa407f
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions GrocyScanner.Core/GrocyClient/GrocyClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,11 @@ public GrocyClient(IHttpClientFactory httpClientFactory, ILogger<GrocyClient> lo

JsonElement.ArrayEnumerator arrayEnumerator = jsonDocument.RootElement.EnumerateArray();
arrayEnumerator.MoveNext();

return new Product
{
Gtin = gtin,
Name = arrayEnumerator.Current.GetProperty("name").GetString()!,
ImageUrl = $"{_grocyConfiguration.Value.BaseUrl}/api/files/productpictures/{Base64Encode(arrayEnumerator.Current.GetProperty("picture_file_name").GetString()!)}"
ImageUrl = $"{_grocyConfiguration.Value.BaseUrl}/api/files/productpictures/{Base64Encode(arrayEnumerator.Current.GetProperty("picture_file_name").GetString() ?? string.Empty)}"
};
}

Expand Down

0 comments on commit caa407f

Please sign in to comment.