From 2600521b961d59cf7a9572213bff8b75c77473c5 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 (cherry picked from commit a5232884268215d2669cfd9bd0e51bfaa4bf69c2) --- 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) }