Skip to content

Commit 3a7bd29

Browse files
authored
Merge pull request #1 from wearespindle/feature/optional-custom-fields
Optional custom fields
2 parents f682688 + 90f3b2a commit 3a7bd29

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

phpipam/client/client.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,12 @@ func (c *Client) GetCustomFieldsSchema(controller string) (out map[string]phpipa
9999
func (c *Client) GetCustomFields(id int, controller string) (out map[string]interface{}, err error) {
100100
var schema map[string]phpipam.CustomField
101101
schema, err = c.GetCustomFieldsSchema(controller)
102-
if err != nil {
103-
return
102+
switch {
103+
case err.Error() == "Error from API (200): No custom fields defined":
104+
err = nil
105+
return
106+
case err != nil:
107+
return
104108
}
105109

106110
out, err = c.getCustomFieldsRequest(id, controller, schema)
@@ -143,8 +147,13 @@ func (c *Client) getCustomFieldsRequest(id int, controller string, schema map[st
143147
func (c *Client) UpdateCustomFields(id int, in map[string]interface{}, controller string) (message string, err error) {
144148
var schema map[string]phpipam.CustomField
145149
schema, err = c.GetCustomFieldsSchema(controller)
146-
if err != nil {
147-
return
150+
switch {
151+
// Ignore this error if the caller is not setting any fields.
152+
case len(in) == 0 && err.Error() == "Error from API (200): No custom fields defined":
153+
err = nil
154+
return
155+
case err != nil:
156+
return
148157
}
149158
message, err = c.updateCustomFieldsRequest(id, in, controller, schema)
150159
return

0 commit comments

Comments
 (0)