From a333f306a3ef983d1ae55b4e9f6fe9181ca74593 Mon Sep 17 00:00:00 2001 From: Jack Lin Date: Mon, 10 Jul 2023 17:12:17 +0800 Subject: [PATCH] fix(server): return 404 if get backing image and backup not found ref: longhorn/longhorn 6266 Signed-off-by: Jack Lin --- api/router.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/api/router.go b/api/router.go index a00cae1ad4..63d78b6b0d 100644 --- a/api/router.go +++ b/api/router.go @@ -8,6 +8,7 @@ import ( "github.com/rancher/go-rancher/client" "github.com/sirupsen/logrus" + "github.com/longhorn/longhorn-manager/datastore" "github.com/longhorn/longhorn-manager/metrics_collector/registry" ) @@ -17,6 +18,12 @@ func HandleError(s *client.Schemas, t HandleFuncWithError) http.Handler { return api.ApiHandler(s, http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) { if err := t(rw, req); err != nil { logrus.WithError(err).Warnf("HTTP handling error") + + if datastore.ErrorIsNotFound(err) { + rw.WriteHeader(http.StatusNotFound) + return + } + apiContext := api.GetApiContext(req) apiContext.WriteErr(err) }