Skip to content

Commit

Permalink
feat: document how to inspect last response in case of error
Browse files Browse the repository at this point in the history
Fixes: #8
  • Loading branch information
aellwein committed Feb 5, 2024
1 parent 435dcf6 commit 73750c9
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,28 @@ This should give you an output like:
DNS zone: { "DomainName": "myowndomain.org", "Ttl": "...", "Serial": "...", "Refresh": "...", "Retry": "...", "Expire": "...", "DnsSecStatus": false
```

Error Handling
--------------

Usually one would expect an ``err`` set only in case of a "hard" or _non-recoverable_ error. This is true
for a technical type of error, like failed REST API call or a broken network connection, but the
Netcup API may set status to "error" in some cases, where you would rather
[assume a warning](https://github.com/mrueg/external-dns-netcup-webhook/issues/5#issuecomment-1913528766).
In such case, the last response from Netcup API is preserved inside the ``NetcupSession`` and can be examined:

```golang
recs, err := session.InfoDnsRecords("myowndomain.org")
if err != nil {
if session.LastResponse != nil &&
sess.LastResponse.Status == string(netcup.StatusError) &&
sess.LastResponse.StatusCode == 5029 {
// no records are found in the DNS zone - Netcup indicates an error here.
println("no error")
} else {
return fmt.Errorf("non-recoverable error on InfoDnsRecords: %v", err)
}
}
```

License
-------
Expand Down

0 comments on commit 73750c9

Please sign in to comment.