feat: handle application not found (#1913)

Signed-off-by: Gaius <gaius.qi@gmail.com>
This commit is contained in:
Gaius 2022-12-12 17:09:17 +08:00
parent 473c5d33f7
commit c20c457abd
No known key found for this signature in database
GPG Key ID: 8B4E5D1290FA2FFB
2 changed files with 20 additions and 6 deletions

View File

@ -996,6 +996,10 @@ func (s *Server) ListApplications(ctx context.Context, req *managerv1.ListApplic
log.Debugf("%s cache miss", cacheKey)
var applications []model.Application
if err := s.db.WithContext(ctx).Find(&applications).Error; err != nil {
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil, status.Error(codes.NotFound, err.Error())
}
return nil, status.Error(codes.Unknown, err.Error())
}

View File

@ -371,12 +371,22 @@ func (mc *managerClient) Get() (any, error) {
Ip: mc.config.Server.AdvertiseIP,
})
if err != nil {
// TODO Compatible with old version manager.
if s, ok := status.FromError(err); ok && s.Code() == codes.Unimplemented {
return DynconfigData{
Scheduler: getSchedulerResp,
Applications: nil,
}, nil
if s, ok := status.FromError(err); ok {
// TODO Compatible with old version manager.
if s.Code() == codes.Unimplemented {
return DynconfigData{
Scheduler: getSchedulerResp,
Applications: nil,
}, nil
}
// Handle application not found.
if s.Code() == codes.NotFound {
return DynconfigData{
Scheduler: getSchedulerResp,
Applications: nil,
}, nil
}
}
return nil, err