@@ -20,11 +20,13 @@ import (
20
20
"context"
21
21
"fmt"
22
22
"net/http"
23
+ "strings"
23
24
24
25
"github.com/vmware/govmomi/vapi/internal"
25
26
)
26
27
27
- // Category provides methods to create, read, update, delete, and enumerate categories.
28
+ // Category provides methods to create, read, update, delete, and enumerate
29
+ // categories.
28
30
type Category struct {
29
31
ID string `json:"id,omitempty"`
30
32
Name string `json:"name,omitempty"`
@@ -92,7 +94,8 @@ func (c *Manager) CreateCategory(ctx context.Context, category *Category) (strin
92
94
return res , c .Do (ctx , url .Request (http .MethodPost , spec ), & res )
93
95
}
94
96
95
- // UpdateCategory can update one or more of the AssociableTypes, Cardinality, Description and Name fields.
97
+ // UpdateCategory updates one or more of the AssociableTypes, Cardinality,
98
+ // Description and Name fields.
96
99
func (c * Manager ) UpdateCategory (ctx context.Context , category * Category ) error {
97
100
spec := struct {
98
101
Category Category `json:"update_spec"`
@@ -108,7 +111,7 @@ func (c *Manager) UpdateCategory(ctx context.Context, category *Category) error
108
111
return c .Do (ctx , url .Request (http .MethodPatch , spec ), nil )
109
112
}
110
113
111
- // DeleteCategory deletes an existing category.
114
+ // DeleteCategory deletes a category.
112
115
func (c * Manager ) DeleteCategory (ctx context.Context , category * Category ) error {
113
116
url := c .Resource (internal .CategoryPath ).WithID (category .ID )
114
117
return c .Do (ctx , url .Request (http .MethodDelete ), nil )
@@ -141,7 +144,7 @@ func (c *Manager) ListCategories(ctx context.Context) ([]string, error) {
141
144
return res , c .Do (ctx , url .Request (http .MethodGet ), & res )
142
145
}
143
146
144
- // GetCategories fetches an array of category information in the system.
147
+ // GetCategories fetches a list of category information in the system.
145
148
func (c * Manager ) GetCategories (ctx context.Context ) ([]Category , error ) {
146
149
ids , err := c .ListCategories (ctx )
147
150
if err != nil {
@@ -152,11 +155,13 @@ func (c *Manager) GetCategories(ctx context.Context) ([]Category, error) {
152
155
for _ , id := range ids {
153
156
category , err := c .GetCategory (ctx , id )
154
157
if err != nil {
155
- return nil , fmt .Errorf ("get category %s: %s" , id , err )
158
+ if strings .Contains (err .Error (), http .StatusText (http .StatusNotFound )) {
159
+ continue // deleted since last fetch
160
+ }
161
+ return nil , fmt .Errorf ("get category %s: %v" , id , err )
156
162
}
157
-
158
163
categories = append (categories , * category )
159
-
160
164
}
165
+
161
166
return categories , nil
162
167
}
0 commit comments