diff options
Diffstat (limited to 'backend/internal/ibd/stockinfo.go')
-rw-r--r-- | backend/internal/ibd/stockinfo.go | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/backend/internal/ibd/stockinfo.go b/backend/internal/ibd/stockinfo.go index e278872..9caa956 100644 --- a/backend/internal/ibd/stockinfo.go +++ b/backend/internal/ibd/stockinfo.go @@ -3,6 +3,7 @@ package ibd import ( "context" "fmt" + "io" "net/http" "net/url" "strconv" @@ -37,16 +38,23 @@ func (c *Client) StockInfo(ctx context.Context, uri string) (*database.StockInfo if err != nil { return nil, err } + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) - if resp.Result.StatusCode != http.StatusOK { + if resp.StatusCode != http.StatusOK { + content, err := io.ReadAll(resp.Body) + if err != nil { + return nil, fmt.Errorf("failed to read response body: %w", err) + } return nil, fmt.Errorf( "unexpected status code %d: %s", - resp.Result.StatusCode, - resp.Result.Content, + resp.StatusCode, + string(content), ) } - node, err := html.Parse(strings.NewReader(resp.Result.Content)) + node, err := html.Parse(resp.Body) if err != nil { return nil, err } |