@@ -562,7 +562,12 @@ func (s *Service) DeleteTunnel(instanceID string) error {
562562 // 调用 NodePass API 删除隧道实例
563563 npClient := nodepass .NewClient (endpoint .URL , endpoint .APIPath , endpoint .APIKey , nil )
564564 if err := npClient .DeleteInstance (instanceID ); err != nil {
565- fmt .Printf ("警告: %v,继续删除本地记录\n " , err )
565+ // 如果收到401或404错误,说明NodePass核心已经没有这个实例了
566+ if strings .Contains (err .Error (), "NodePass API 返回错误: 401" ) || strings .Contains (err .Error (), "NodePass API 返回错误: 404" ) {
567+ log .Warnf ("[API] NodePass API 返回401/404错误,实例 %s 可能已不存在,继续删除本地记录" , instanceID )
568+ } else {
569+ log .Warnf ("[API] NodePass API 删除失败: %v,继续删除本地记录" , err )
570+ }
566571 }
567572
568573 // 删除隧道记录
@@ -1035,9 +1040,9 @@ func (s *Service) DeleteTunnelAndWait(instanceID string, timeout time.Duration,
10351040 // 调用 NodePass API 删除实例
10361041 npClient := nodepass .NewClient (endpoint .URL , endpoint .APIPath , endpoint .APIKey , nil )
10371042 if err := npClient .DeleteInstance (instanceID ); err != nil {
1038- // 如果收到401错误 ,说明NodePass核心已经没有这个实例了,按删除成功处理
1039- if strings .Contains (err .Error (), "NodePass API 返回错误: 401" ) {
1040- log .Warnf ("[API] NodePass API 返回401错误 ,实例 %s 可能已不存在,继续删除本地记录" , instanceID )
1043+ // 如果收到401或404错误 ,说明NodePass核心已经没有这个实例了,按删除成功处理
1044+ if strings .Contains (err .Error (), "NodePass API 返回错误: 401" ) || strings . Contains ( err . Error (), "NodePass API 返回错误: 404" ) {
1045+ log .Warnf ("[API] NodePass API 返回401/404错误 ,实例 %s 可能已不存在,继续删除本地记录" , instanceID )
10411046 } else {
10421047 return err
10431048 }
0 commit comments