Skip to content

Commit

Permalink
Merge pull request #76 from jadolg/remove-error-codes
Browse files Browse the repository at this point in the history
Stop using error codes different from 200 when a test fails or timeouts
  • Loading branch information
jadolg authored Dec 17, 2023
2 parents 7a40566 + 8c0aa15 commit 0a9c8e2
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 8 deletions.
14 changes: 10 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,17 @@ <h3 v-if="proxyLocation !== ''">Address: {{ proxyAddress }}</h3>
'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 = '';
});
Expand Down
10 changes: 7 additions & 3 deletions server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
2 changes: 1 addition & 1 deletion server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

0 comments on commit 0a9c8e2

Please sign in to comment.