feat: enhance proxy error handling and simplify response logic

- Add error response with detailed message when proxy request fails - Remove conditional HTML content handling for streamlined response copying - Import fmt package for error formatting This improves error visibility for failed proxy requests and reduces code complexity by unifying response handling.

lemon-mint committed Oct 31, 2025 at 13:50 UTC 308da191960a6ff1e02ec2128e5af1655388b149
1 file changed +4 -12
cmd/webclient/main_js.go
+4 -12
@@ -2,6 +2,7 @@ package main
2
3 import (
4 "context"
5 + "fmt"
6 "io"
7 "mime"
8 "net"
@@ -81,6 +82,7 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
82 resp, err := client.Do(r)
83 if err != nil {
84 log.Error().Err(err).Msgf("Failed to proxy request to %s", r.URL.String())
85 + http.Error(w, fmt.Sprintf("Failed to proxy request to %s, err: %v", r.URL.String(), err), http.StatusBadGateway)
86 return
87 }
88 defer resp.Body.Close()
@@ -89,18 +91,8 @@ func (p *Proxy) ServeHTTP(w http.ResponseWriter, r *http.Request) {
91 w.Header()[key] = value
92 }
93
92 - if r.Context().Value("http.request.mode").(string) == "navigate" &&
93 - IsHTMLContentType(resp.Header.Get("Content-Type")) {
94 - log.Debug().Msgf("HTML content received")
95 -
96 - w.WriteHeader(resp.StatusCode)
97 - io.Copy(w, resp.Body)
98 - } else {
99 - log.Debug().Msgf("Non-HTML content received")
100 -
101 - w.WriteHeader(resp.StatusCode)
102 - io.Copy(w, resp.Body)
103 - }
94 + w.WriteHeader(resp.StatusCode)
95 + io.Copy(w, resp.Body)
96 }
97
98 func main() {