resource: handle `ErrWatchClosed` in `WatchList` endpoint (#17289)

This commit is contained in:
Dan Upton 2023-05-15 12:35:10 +01:00 committed by GitHub
parent 879b775459
commit 0a38fc1a2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 1 deletions

View File

@ -4,6 +4,8 @@
package resource
import (
"errors"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
@ -51,7 +53,10 @@ func (s *Server) WatchList(req *pbresource.WatchListRequest, stream pbresource.R
for {
event, err := watch.Next(stream.Context())
if err != nil {
switch {
case errors.Is(err, storage.ErrWatchClosed):
return status.Error(codes.Aborted, "watch closed by the storage backend (possibly due to snapshot restoration)")
case err != nil:
return status.Errorf(codes.Internal, "failed next: %v", err)
}