summaryrefslogtreecommitdiff
path: root/api/handlers.go
diff options
context:
space:
mode:
Diffstat (limited to 'api/handlers.go')
-rw-r--r--api/handlers.go10
1 files changed, 9 insertions, 1 deletions
diff --git a/api/handlers.go b/api/handlers.go
index 04fcc23..93f605e 100644
--- a/api/handlers.go
+++ b/api/handlers.go
@@ -258,6 +258,8 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) {
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
b, _ := io.ReadAll(resp.Body)
+ resp.Body.Close()
+
log.Printf("article request failed: user=%s article=%s status=%d body=%s (%dms)",
username, article, resp.StatusCode, string(b), elapsed)
h.db.LogApiCall(ctx, &db.ApiLogEntry{
@@ -268,7 +270,13 @@ func (h *Handler) GetArticle(w http.ResponseWriter, r *http.Request) {
Error: string(b),
RequestURL: queryURL,
})
- http.Error(w, string(b), resp.StatusCode)
+
+ w.Header().Set("Content-Type", "application/json")
+ w.WriteHeader(resp.StatusCode)
+ w.Write(b) //nolint:errcheck
+ if f, ok := w.(http.Flusher); ok {
+ f.Flush()
+ }
return
}