From 64880261c28c6d90a2300a6360141bcfe531a680 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Thu, 28 Mar 2024 21:56:36 +0300 Subject: [PATCH] fix: some http status error codes are not sent to client du to order --- cmd/hvpn-node/hvpn-node.go | 2 +- handlers.go | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/cmd/hvpn-node/hvpn-node.go b/cmd/hvpn-node/hvpn-node.go index e1ad5f6..5ac9083 100644 --- a/cmd/hvpn-node/hvpn-node.go +++ b/cmd/hvpn-node/hvpn-node.go @@ -65,7 +65,7 @@ func run(ctx *cli.Context) { apiMux.HandleFunc("POST /peer", hvpnnode3.HandlePostPeer(wgLink)) apiMux.HandleFunc("DELETE /peer/{pubkey}", hvpnnode3.HandleDeletePeer(wgLink)) apiMux.HandleFunc("GET /peers", hvpnnode3.HandleGetPeers(wgLink)) - apiMux.HandleFunc("GET /peer/new", hvpnnode3.HandleGetCreatePeer(wgLink)) + apiMux.HandleFunc("GET /peer", hvpnnode3.HandleGetCreatePeer(wgLink)) var handler http.Handler = apiMux handler = hvpnnode3.HttpAuthToken(handler, ctx.String("http-api-key")) diff --git a/handlers.go b/handlers.go index a20fdea..e226767 100644 --- a/handlers.go +++ b/handlers.go @@ -52,12 +52,13 @@ func HandleGetPeer(wgLink *WGLink) http.HandlerFunc { peer, err := wgLink.GetPeer(pubkey) if err != nil { if errors.Is(err, proto.PeerDoesNotExist){ + w.WriteHeader(http.StatusNotFound) json.NewEncoder(w).Encode( proto.ErrJSONResponse{Message: "Peer does not exist"}, ) - w.WriteHeader(http.StatusNotFound) return } + slog.Error(err.Error()) w.WriteHeader(http.StatusInternalServerError) return }