@@ -107,45 +107,44 @@ func queryAddress(writ http.ResponseWriter, req *http.Request) {
107107 writ .Header ().Set ("Content-Type" , "application/json" )
108108
109109 keys , ok := req .URL .Query ()["namespace" ]
110-
111110 if ! ok {
112111 http .Error (writ , "Missing 'namespace' query" , http .StatusBadRequest )
113112 return
114113 }
115114
116- namespace := keys [0 ]
117-
118- fcClient , err := client .New (containerdSockPath + ".ttrpc" )
115+ sock := containerdSockPath + ".ttrpc"
116+ fcClient , err := client .New (sock )
119117 if err != nil {
120118 logger .WithError (err ).Error ("could not create firecracker client" )
121- http .Error (writ , "Internal server error" , http .StatusInternalServerError )
119+ http .Error (writ , fmt . Sprintf ( "failed to connect %q" , sock ) , http .StatusInternalServerError )
122120 return
123121 }
124122 defer fcClient .Close ()
125123
124+ namespace := keys [0 ]
126125 ctx := namespaces .WithNamespace (req .Context (), namespace )
127126 vmInfo , err := fcClient .GetVMInfo (ctx , & proto.GetVMInfoRequest {VMID : namespace })
128127 if err != nil {
129128 logger .WithField ("VMID" , namespace ).WithError (err ).Error ("unable to retrieve VM Info" )
130- http .Error (writ , "Internal server error " , http .StatusInternalServerError )
129+ http .Error (writ , fmt . Sprintf ( "failed to get VM %q " , namespace ), http .StatusNotFound )
131130 return
132131 }
133132
134133 writ .WriteHeader (http .StatusOK )
135134
136- response , err := json . Marshal ( proxyaddress.Response {
135+ result := proxyaddress.Response {
137136 Network : "unix" ,
138137 Address : vmInfo .VSockPath ,
139138 SnapshotterPort : strconv .Itoa (remotePort ),
140139 MetricsPort : strconv .Itoa (metricsRemotePort ),
141140 Labels : map [string ]string {
142141 "VMID" : namespace ,
143142 },
144- })
143+ }
144+ serialized , err := json .Marshal (& result )
145145 if err != nil {
146- http .Error (writ , "Internal server error" , http .StatusInternalServerError )
146+ http .Error (writ , fmt . Sprintf ( "failed to marshal %+v" , result ) , http .StatusInternalServerError )
147147 return
148148 }
149-
150- writ .Write (response )
149+ writ .Write (serialized )
151150}
0 commit comments