aboutsummaryrefslogtreecommitdiff
path: root/internal/ogtags
diff options
context:
space:
mode:
authorJason Cameron <git@jasoncameron.dev>2025-04-22 20:31:19 -0400
committerGitHub <noreply@github.com>2025-04-22 20:31:19 -0400
commit78bb67fbf79bce6abed9d4e416ca1d10ed7dc12b (patch)
tree160698d9ffa50eb2a2911b906dfa2c1feb976cf2 /internal/ogtags
parent2db4105479e5920e983b15b0341104d6e572c1ea (diff)
downloadanubis-78bb67fbf79bce6abed9d4e416ca1d10ed7dc12b.tar.xz
anubis-78bb67fbf79bce6abed9d4e416ca1d10ed7dc12b.zip
fix: improve error handling and create the json encoder once #331 (#332)
* fix: improve error handling for resource closing and JSON encoding in MakeChallenge * chore: update CHANGELOG with recent changes and improvements * refactor: simplify RenderIndex function and improve error handling --------- Signed-off-by: Jason Cameron <git@jasoncameron.dev>
Diffstat (limited to 'internal/ogtags')
-rw-r--r--internal/ogtags/fetch.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/internal/ogtags/fetch.go b/internal/ogtags/fetch.go
index d4db711..7e02eca 100644
--- a/internal/ogtags/fetch.go
+++ b/internal/ogtags/fetch.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"golang.org/x/net/html"
+ "io"
"log/slog"
"mime"
"net"
@@ -26,7 +27,12 @@ func (c *OGTagCache) fetchHTMLDocument(urlStr string) (*html.Node, error) {
return nil, fmt.Errorf("http get failed: %w", err)
}
// this defer will call MaxBytesReader's Close, which closes the original body.
- defer resp.Body.Close()
+ defer func(Body io.ReadCloser) {
+ err := Body.Close()
+ if err != nil {
+ slog.Debug("og: error closing response body", "url", urlStr, "error", err)
+ }
+ }(resp.Body)
if resp.StatusCode != http.StatusOK {
slog.Debug("og: received non-OK status code", "url", urlStr, "status", resp.StatusCode)