From 4ae1a4eddc47fc53e8b224f8103e15d837c7f9e1 Mon Sep 17 00:00:00 2001 From: Achmad Irianto Eka Putra Date: Mon, 28 Aug 2023 20:57:28 +0700 Subject: [PATCH] fix: unhandled error --- proxy/proxy.go | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/proxy/proxy.go b/proxy/proxy.go index ab662e2..2948a93 100644 --- a/proxy/proxy.go +++ b/proxy/proxy.go @@ -66,7 +66,9 @@ func (p *Proxy) handleHTTP(w http.ResponseWriter, r *http.Request) { http.Error(w, err.Error(), http.StatusServiceUnavailable) return } - defer resp.Body.Close() + defer func(Body io.ReadCloser) { + _ = Body.Close() + }(resp.Body) // copy all headers from the response to the client copyHeader(w.Header(), resp.Header) @@ -76,8 +78,10 @@ func (p *Proxy) handleHTTP(w http.ResponseWriter, r *http.Request) { // transfer bytes from src to dst until either EOF is reached on src or an error occurs func transfer(destination io.WriteCloser, source io.ReadCloser) { - defer destination.Close() - defer source.Close() + defer func() { + _ = destination.Close() + _ = source.Close() + }() _, _ = io.Copy(destination, source) }