Compare commits

...

2 Commits

Author SHA1 Message Date
Bastian de Byl
f18e21f181 main return only one product for GetProductById 2023-05-12 10:46:54 -04:00
Bastian de Byl
d56cf589da main correct the output of GetProductById 2023-05-12 03:14:07 -04:00

View File

@@ -308,11 +308,15 @@ func (s *Client) GetProductById(id string) (*SnipcartProduct, error) {
defer response.Body.Close()
var product SnipcartProduct
err = json.NewDecoder(response.Body).Decode(&product)
var products SnipcartProductsResponse
err = json.NewDecoder(response.Body).Decode(&products)
if err != nil {
return nil, err
}
return &product, nil
if len(products.Items) < 1 {
return nil, fmt.Errorf("no products with id '%s'", id)
}
return &products.Items[0], nil
}