fix: return 404 (not 502) when function Service is gone (DNS no such host)

After trigger/function destroy the Service is deleted, DNS lookup fails with
'no such host'. Previously InvokeFunction returned 502 which kept the test
script retrying for 120s. Now returns 404 — endpoint removed, test passes.

Operator: naeel/sless-operator:v0.1.18
This commit is contained in:
“Naeel”
2026-03-09 20:03:08 +04:00
parent 0b0a50d03a
commit 72e4137b0a
+6
View File
@@ -59,6 +59,12 @@ func (h *Handler) InvokeFunction(w http.ResponseWriter, r *http.Request) {
resp, err := httpClient.Do(proxyReq) resp, err := httpClient.Do(proxyReq)
if err != nil { if err != nil {
// "no such host" — Service не существует (функция удалена), возвращаем 404.
// Это отличается от временной сетевой ошибки: NXDOMAIN строго означает отсутствие записи.
if strings.Contains(err.Error(), "no such host") {
writeJSON(w, http.StatusNotFound, errResp("function not found"))
return
}
h.Log.Error("invoke: function unreachable", "err", err, "ns", ns, "fn", name, "target", target) h.Log.Error("invoke: function unreachable", "err", err, "ns", ns, "fn", name, "target", target)
writeJSON(w, http.StatusBadGateway, errResp("function unreachable: "+err.Error())) writeJSON(w, http.StatusBadGateway, errResp("function unreachable: "+err.Error()))
return return