Skip to content

Report the HTTP status and validation errors of LiveDNS - #19

Open
n-rodriguez wants to merge 1 commit into
libdns:masterfrom
jbox-web:fix/validation-error-message
Open

n-rodriguez wants to merge 1 commit into
libdns:masterfrom
jbox-web:fix/validation-error-message

Conversation

@n-rodriguez

Copy link
Copy Markdown
Contributor

Problem

LiveDNS validation errors carry neither code nor message, only a list of errors:

{"status": "error", "errors": [{"location": "body", "name": "items", "description": "String does not match expected pattern"}]}

doRequest only reported code and message, so such an error surfaced as LiveDNS returned a 0 (), with nothing to tell what was rejected. A body that is not JSON (a 403 page from a gateway, for instance) returned the JSON decoding error (invalid character '<' looking for beginning of value) instead of the HTTP status. The Location field of gandiErrors was also read from a body key, while LiveDNS sends it as location.

Change

  • Fall back on the HTTP status code when the body has no code, and on the HTTP status text when it has no message; the returned status carries that code too, so callers checking for a 404 keep working.
  • Append each validation error to the message: LiveDNS returned a 400 (Bad Request): body items: String does not match expected pattern.
  • Keep the HTTP status when the body is not JSON: LiveDNS returned a 403 (Forbidden).
  • Read Location from the location key.

Tests

errors_test.go covers a validation error, an error with code and message (unchanged behaviour), and a non-JSON body. The validation and non-JSON tests fail without the change, and the validation test also fails with the former body tag.

This is independent from #18; both touch client.go in different functions.

🤖 Generated with Claude Code

LiveDNS validation errors carry neither code nor message, only a list of
errors, so they surfaced as "LiveDNS returned a 0 ()". A body that is not
JSON returned the decoding error instead of the HTTP status.

- Update client.go: fall back on the HTTP status code and text, append
  each validation error, and keep the status when the body is not JSON
- Update gandi.go: read the error location from its "location" key
- Add errors_test.go: cover validation errors, code and message, and a
  non-JSON body

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant