fix: handle JSON decode error in monocular search

The return value of json.NewDecoder().Decode() was not being checked,
so malformed responses from the search API would silently return empty
results instead of reporting an error.

Signed-off-by: Woravit Ariyakunatorn <wariyakunatorn@gmail.com>
pull/31951/head
Woravit Ariyakunatorn 7 months ago
parent 42f78ba60e
commit 2b3f621450

@ -135,7 +135,9 @@ func (c *Client) Search(term string) ([]SearchResult, error) {
result := &searchResponse{} result := &searchResponse{}
json.NewDecoder(res.Body).Decode(result) if err := json.NewDecoder(res.Body).Decode(result); err != nil {
return nil, fmt.Errorf("failed to decode response from %s: %w", p.String(), err)
}
return result.Data, nil return result.Data, nil
} }

Loading…
Cancel
Save