Skip to content

Commit

Permalink
Merge pull request #89 from akamai/dns_maint
Browse files Browse the repository at this point in the history
add addtl conditions to record error checks.
  • Loading branch information
edglynes committed May 12, 2020
2 parents 8db108f + 282cdb0 commit aac49c7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
28 changes: 26 additions & 2 deletions configdns-v2/errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ type ConfigDNSError interface {
NotFound() bool
FailedToSave() bool
ValidationFailed() bool
ConcurrencyConflict() bool
}

func IsConfigDNSError(e error) bool {
Expand All @@ -35,7 +36,12 @@ func (e *ZoneError) Network() bool {
func (e *ZoneError) NotFound() bool {
if e.err == nil && e.httpErrorMessage == "" && e.apiErrorMessage == "" {
return true
}
} else if e.err != nil {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 404 {
return true
}
}
return false
}

Expand All @@ -50,6 +56,15 @@ func (e *ZoneError) ValidationFailed() bool {
return false
}

func (e *ZoneError) ConcurrencyConflict() bool {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 409 {
return true
}
return false
}


func (e *ZoneError) Error() string {
if e.Network() {
return fmt.Sprintf("Zone \"%s\" network error: [%s]", e.zoneName, e.httpErrorMessage)
Expand All @@ -59,6 +74,10 @@ func (e *ZoneError) Error() string {
return fmt.Sprintf("Zone \"%s\" not found.", e.zoneName)
}

if e.ConcurrencyConflict() {
return fmt.Sprintf("Modification Confict: [%s]", e.apiErrorMessage)
}

if e.FailedToSave() {
return fmt.Sprintf("Zone \"%s\" failed to save: [%s]", e.zoneName, e.err.Error())
}
Expand Down Expand Up @@ -91,6 +110,11 @@ func (e *RecordError) Network() bool {
func (e *RecordError) NotFound() bool {
if e.err == nil && e.httpErrorMessage == "" && e.apiErrorMessage == "" {
return true
} else if e.err != nil {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Response.StatusCode == 404 {
return true
}
}
return false
}
Expand All @@ -111,7 +135,7 @@ func (e *RecordError) ValidationFailed() bool {

func (e *RecordError) ConcurrencyConflict() bool {
_, ok := e.err.(client.APIError)
if ok && e.err.(client.APIError).Status == 409 {
if ok && e.err.(client.APIError).Response.StatusCode == 409 {
return true
}
return false
Expand Down
6 changes: 4 additions & 2 deletions configdns-v2/record.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,10 @@ func (record *RecordBody) Delete(zone string, recLock ...bool) error {

// API error
if client.IsError(res) {
err := client.NewAPIError(res)
return &RecordError{fieldName: record.Name, apiErrorMessage: err.Detail, err: err}
if res.StatusCode != 404 {
err := client.NewAPIError(res)
return &RecordError{fieldName: record.Name, apiErrorMessage: err.Detail, err: err}
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions configdns-v2/zone.go
Original file line number Diff line number Diff line change
Expand Up @@ -473,8 +473,10 @@ func (zone *ZoneCreate) Delete(zonequerystring ZoneQueryString) error {

// API error
if client.IsError(res) {
err := client.NewAPIError(res)
return &ZoneError{zoneName: zone.Zone, apiErrorMessage: err.Detail, err: err}
if res.StatusCode != 404 {
err := client.NewAPIError(res)
return &ZoneError{zoneName: zone.Zone, apiErrorMessage: err.Detail, err: err}
}
}

return nil
Expand Down

0 comments on commit aac49c7

Please sign in to comment.