From df8757900624b998b003d431eb00505cf61136d5 Mon Sep 17 00:00:00 2001 From: "Jorge Alberto Diaz Orozco (Akiel)" Date: Fri, 1 Dec 2023 18:51:06 +0100 Subject: [PATCH 1/2] Stop using error codes different from 200 when a test fails or timeouts --- server.go | 10 +++++++--- server_test.go | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/server.go b/server.go index 5ac8e16..3689d7a 100644 --- a/server.go +++ b/server.go @@ -88,10 +88,14 @@ func getRouter(ipv4Only bool) (*http.ServeMux, error) { } func fillCheckError(w http.ResponseWriter, err error, address string) { + message := fmt.Sprintf("Unable to get information for address %s", address) if err, ok := err.(net.Error); ok && err.Timeout() { - http.Error(w, fmt.Sprintf("Timeout getting information for address %s", address), http.StatusGatewayTimeout) - } else { - http.Error(w, fmt.Sprintf("Unable to get information for address %s", address), http.StatusBadGateway) + message = fmt.Sprintf("Timeout getting information for address %s", address) + } + + _, err = w.Write([]byte(message)) + if err != nil { + log.Errorf("Impossible to write response %v", err) } } diff --git a/server_test.go b/server_test.go index f0a44d9..55e7072 100644 --- a/server_test.go +++ b/server_test.go @@ -58,5 +58,5 @@ func TestGetProxyDetailsFromServerTimeout(t *testing.T) { rr := httptest.NewRecorder() router.ServeHTTP(rr, req) - assert.Equal(t, http.StatusGatewayTimeout, rr.Code) + assert.Equal(t, http.StatusOK, rr.Code) } From 8c0aa15dd0406fe15bbb65501f19633227d2e3a1 Mon Sep 17 00:00:00 2001 From: "Jorge Alberto Diaz Orozco (Akiel)" Date: Sun, 17 Dec 2023 20:12:24 +0100 Subject: [PATCH 2/2] Adjust the frontend, so it doesn't use error codes but the actual content of the response --- index.html | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/index.html b/index.html index 26fdeeb..96b9cd9 100644 --- a/index.html +++ b/index.html @@ -54,11 +54,17 @@

Address: {{ proxyAddress }}

'address': this.proxy } ).then(response => { - this.proxyStatus = 'Online'; - this.proxyAddress = response.data.YourFuckingIPAddress; - this.proxyLocation = response.data.YourFuckingLocation; + if (typeof response.data === 'string' && response.data.startsWith('Unable to get information for address')) { + this.proxyStatus = 'Offline'; + this.proxyAddress = ''; + this.proxyLocation = ''; + } else { + this.proxyStatus = 'Online'; + this.proxyAddress = response.data.YourFuckingIPAddress; + this.proxyLocation = response.data.YourFuckingLocation; + } }).catch(error => { - this.proxyStatus = 'Offline'; + this.proxyStatus = 'Server Error'; this.proxyAddress = ''; this.proxyLocation = ''; });