commit 58319a28da3fc8976552613c27fc7b90f1a1968d
parent 91156ec9a54651b4c1eef7020e3b4cd71e3e23e7
Author: MichaĆ M. Sapka <michal@sapka.me>
Date: Sat, 15 Jul 2023 23:19:21 +0200
feat: basic error handling
Diffstat:
1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/main.go b/main.go
@@ -27,8 +27,8 @@ func init() {
func main() {
// Remove comments to act as standard process
- serveProxy()
- return
+ // serveProxy()
+ // return
cntxt := &daemon.Context{
PidFileName: "plaprox.pid",
@@ -62,12 +62,17 @@ func serveProxy() {
}
}
+func handleErrror(r *http.Request, error error) {
+ log.Print("error processing "+r.URL.Path+": ", error)
+}
+
func Proxy(w http.ResponseWriter, r *http.Request) {
log.Print("trying to proxy " + r.URL.Path)
req, err := http.NewRequest(r.Method, "https://plausible.io"+r.URL.Path, r.Body)
if err != nil {
- log.Fatal(err)
+ handleErrror(r, err)
return
+
}
for key, values := range r.Header {
@@ -82,7 +87,7 @@ func Proxy(w http.ResponseWriter, r *http.Request) {
resp, err := Client.Do(req)
if err != nil {
- log.Fatal(err)
+ handleErrror(r, err)
return
}
@@ -90,7 +95,7 @@ func Proxy(w http.ResponseWriter, r *http.Request) {
bodyBytes, err := io.ReadAll(resp.Body)
if err != nil {
- log.Fatal(err)
+ handleErrror(r, err)
return
}