Skip to content

Commit

Permalink
Merge pull request #8 from yankooo/compatible-request-404
Browse files Browse the repository at this point in the history
Compatible request 404
  • Loading branch information
yankooo authored Sep 7, 2020
2 parents 4b15f02 + f88d5e8 commit 6b86cca
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
29 changes: 12 additions & 17 deletions agollo.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func Init(opts ...Option) (err error) {
} else {
err = s.LoadConfigFile(nil)
if err != nil {
err = errors.WithMessage(err, "syncConfig init")
err = errors.WithMessage(err, "LoadConfigFile init")
return
}
}
Expand Down Expand Up @@ -162,31 +162,22 @@ func (s *service) syncConfig(isInit bool, nm []*namespace) error {
if nm == nil {
nm = s.namespaceList
}
var event map[string]*ChangeEvent
event = make(map[string]*ChangeEvent)
var retErr *multierror.Error
var event = make(map[string]*ChangeEvent)
for _, v := range nm {
cfg, err := s.ConfigCenter.SyncConfig(v.NamespaceName, v.releaseKey, v.NotificationId)
if err != nil {
logger.LogError("sync config failed %v", err)
var retErr = apollo.NewMutliError()
retErr = multierror.Append(retErr, err)
if err != nil || (cfg == nil && isInit) {
logger.LogError(fmt.Sprintf("sync namespace [%s] config failed %v", v.NamespaceName, err))
retErr = multierror.Append(apollo.NewMutliError(), err)
if isInit {
path := getConfigPath(v.NamespaceName)
cfg, err = loadConfigFile(path)
if err != nil {
err = errors.WithMessage(err, "loadConfigFile "+v.NamespaceName)
return multierror.Append(retErr, err)
retErr = multierror.Append(retErr, errors.WithMessage(err, "loadConfigFile "+v.NamespaceName))
continue
}
}
}
if cfg == nil && isInit {
path := getConfigPath(v.NamespaceName)
cfg, err = loadConfigFile(path)
if err != nil {
err = errors.WithMessage(err, "loadConfigFile"+path)
return err
}
}
if cfg != nil {
event[v.NamespaceName] = getChangeEvent(cfg)
updateCache(cfg, v, event[v.NamespaceName])
Expand All @@ -199,6 +190,10 @@ func (s *service) syncConfig(isInit bool, nm []*namespace) error {
}
}
}
// err only print log, dont return, cause maybe namespace success once in namespace list.
if retErr != nil {
logger.LogError(fmt.Sprintf("syncConfig failed %s", retErr.Error()))
}
return nil
}

Expand Down
5 changes: 4 additions & 1 deletion internal/apollo/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,11 @@ func request(requestUrl string, timeout time.Duration, callBack *CallBack) (inte
case http.StatusGatewayTimeout:
logger.LogInfo("Gateway Timeout")
return nil, nil
case http.StatusNotFound:
logger.LogError("%s Not Found, resp code: %d", requestUrl, res.StatusCode)
return nil, nil
default:
logger.LogError("Connect Apollo Server Fail,StatusCode: %v", res.StatusCode)
logger.LogError("Connect Apollo Server Fail,StatusCode: %d", res.StatusCode)
err = errors.WithMessage(ErrInvalidHttpStatus, "status "+strconv.Itoa(res.StatusCode))
retErr = multierror.Append(retErr, err)
continue
Expand Down

0 comments on commit 6b86cca

Please sign in to comment.