Skip to content

Commit

Permalink
Merge pull request #312 from mikenairn/fix_azure_err_parser
Browse files Browse the repository at this point in the history
fix: Azure provider error parsing
  • Loading branch information
maleck13 authored Nov 22, 2024
2 parents 929fe20 + 397dda5 commit 53115e6
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
8 changes: 5 additions & 3 deletions internal/external-dns/provider/azure/azure.go
Original file line number Diff line number Diff line change
Expand Up @@ -466,8 +466,10 @@ func CleanAzureError(err error) error {
reg := regexp.MustCompile(`\"message\": \".*\"`)
errMsg := err.Error()
msg := reg.FindString(errMsg)
msgBits := strings.SplitAfterN(msg, ":", 2)
msgBits = strings.Split(msgBits[1], `"`)
msg = msgBits[1]
if msgBits := strings.SplitAfterN(msg, ":", 2); len(msgBits) > 1 {
if msgBits = strings.Split(msgBits[1], `"`); len(msgBits) > 1 {
msg = msgBits[1]
}
}
return errors.New(msg)
}
8 changes: 8 additions & 0 deletions internal/external-dns/provider/azure/azure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,14 @@ func TestCleanAzureError(t *testing.T) {
Expect(err.Error()).To(Equal("The following locations specified in the geoMapping property for endpoint ‘foo-example-com’ are not supported: NOTAGEOCODE. For a list of supported locations, see the Traffic Manager documentation."))
},
},
{
name: "cleans up error that doesn't match expected format",
err: fmt.Errorf("some other error"),
Verify: func(err error) {
Expect(err).ToNot(BeNil())
Expect(err.Error()).To(Equal(""))
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 53115e6

Please sign in to comment.