fix: some http status error codes are not sent to client du to order
This commit is contained in:
		
							parent
							
								
									7d1a0cdbdc
								
							
						
					
					
						commit
						64880261c2
					
				@ -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"))
 | 
			
		||||
 | 
			
		||||
@ -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
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user