Skip to content

Commit b3ef5de

Browse files
authored
Merge pull request #244 from xmidt-org/fix/itemToInternalWebhook
updated unmarshaling logic
2 parents 82d2317 + 80187b0 commit b3ef5de

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

internalWebhook.go

+7-6
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,19 @@ func ItemToInternalWebhook(i model.Item) (Register, error) {
8282
return nil, err
8383
}
8484

85+
err = json.Unmarshal(encodedWebhook, &v2)
86+
if err == nil && v2.Registration.CanonicalName != "" {
87+
return v2, nil
88+
} else if err != nil {
89+
errs = errors.Join(errs, fmt.Errorf("RegistryV2 unmarshal error: %s", err))
90+
}
91+
8592
err = json.Unmarshal(encodedWebhook, &v1)
8693
if err == nil {
8794
return v1, nil
8895
}
8996

9097
errs = errors.Join(errs, fmt.Errorf("RegistryV1 unmarshal error: %s", err))
91-
err = json.Unmarshal(encodedWebhook, &v2)
92-
if err == nil {
93-
return v2, nil
94-
}
95-
96-
errs = errors.Join(errs, fmt.Errorf("RegistryV2 unmarshal error: %s", err))
9798

9899
return nil, fmt.Errorf("could not unmarshal data into either RegistryV1 or RegistryV2: %s", errs)
99100
}

0 commit comments

Comments
 (0)