Skip to content

Commit

Permalink
fix(server): return 404 if get backing image and backup not found
Browse files Browse the repository at this point in the history
ref: longhorn/longhorn 6266

Signed-off-by: Jack Lin <jack.lin@suse.com>
  • Loading branch information
ChanYiLin committed Jul 10, 2023
1 parent 6f809b3 commit d80e226
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions api/backingimage.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/pkg/errors"
"github.com/rancher/go-rancher/api"
"github.com/rancher/go-rancher/client"
Expand Down Expand Up @@ -36,6 +37,10 @@ func (s *Server) BackingImageGet(rw http.ResponseWriter, req *http.Request) erro

bi, err := s.m.GetBackingImage(id)
if err != nil {
if datastore.ErrorIsNotFound(err) {
rw.WriteHeader(http.StatusNotFound)
return nil
}
return errors.Wrapf(err, "failed to get backing image '%s'", id)
}

Expand Down
5 changes: 5 additions & 0 deletions api/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/longhorn/longhorn-manager/datastore"
"github.com/pkg/errors"
"github.com/rancher/go-rancher/api"
"github.com/rancher/go-rancher/client"
Expand Down Expand Up @@ -47,6 +48,10 @@ func (s *Server) BackupVolumeGet(w http.ResponseWriter, req *http.Request) error

bv, err := s.m.GetBackupVolume(volName)
if err != nil {
if datastore.ErrorIsNotFound(err) {
w.WriteHeader(http.StatusNotFound)
return nil
}
return errors.Wrapf(err, "failed to get backup volume '%s'", volName)
}
apiContext.Write(toBackupVolumeResource(bv, apiContext))
Expand Down

0 comments on commit d80e226

Please sign in to comment.