Skip to content

Commit

Permalink
Added error logging
Browse files Browse the repository at this point in the history
  • Loading branch information
evg4b committed Jul 11, 2022
1 parent a90fa10 commit 9fb7081
Showing 1 changed file with 22 additions and 4 deletions.
26 changes: 22 additions & 4 deletions internal/proxy/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,10 @@ func (pm *ProxyMiddleware) Wrap(next infrastrucure.HandlerFunc) infrastrucure.Ha

req2, err := http.NewRequest(req.Method, url, req.Body)
if err != nil {
log.Print(err)
pterm.Error.Println(err)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
return
}

Expand All @@ -60,7 +63,10 @@ func (pm *ProxyMiddleware) Wrap(next infrastrucure.HandlerFunc) infrastrucure.Ha
if strings.ToLower(n) == "origin" || strings.ToLower(n) == "referer" {
h, err = pm.replcaer.ToTarget(h)
if err != nil {
panic(err)
pterm.Error.Println(err)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))
}
}

Expand All @@ -86,8 +92,11 @@ func (pm *ProxyMiddleware) Wrap(next infrastrucure.HandlerFunc) infrastrucure.Ha

resp, err := client.Do(req2)
if err != nil {
pterm.Error.Println(err)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))

return
}

Expand All @@ -102,7 +111,12 @@ func (pm *ProxyMiddleware) Wrap(next infrastrucure.HandlerFunc) infrastrucure.Ha
if strings.ToLower(h) == "location" {
v, err = pm.replcaer.ToSource(v, req.Host)
if err != nil {
panic(err)
pterm.Error.Println(err)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))

return
}
}
w.Header().Add(h, v)
Expand All @@ -114,7 +128,11 @@ func (pm *ProxyMiddleware) Wrap(next infrastrucure.HandlerFunc) infrastrucure.Ha

_, err = io.Copy(w, resp.Body)
if err != nil {
log.Println(err)
pterm.Error.Println(err)

w.WriteHeader(http.StatusInternalServerError)
w.Write([]byte(err.Error()))

return
}

Expand Down

0 comments on commit 9fb7081

Please sign in to comment.