Skip to content

[Domains] Throw an error instead of suppressing#1049

Merged
saeedvaziry merged 4 commits intovitodeploy:3.xfrom
RichardAnderson:fix/dns-errors
Mar 16, 2026
Merged

[Domains] Throw an error instead of suppressing#1049
saeedvaziry merged 4 commits intovitodeploy:3.xfrom
RichardAnderson:fix/dns-errors

Conversation

@RichardAnderson
Copy link
Member

@RichardAnderson RichardAnderson commented Mar 16, 2026

This pull request improves error handling and transactional integrity for domain and DNS record operations. It ensures that failures during DNS record synchronization or domain creation are properly surfaced to the user and that domains are not persisted if DNS record sync fails. The changes also update tests to verify these new behaviors.

Error handling and transactional integrity improvements:

  • Wrapped domain creation in a database transaction in AddDomain.php, ensuring that if DNS record synchronization fails, the domain is not persisted and a validation error is returned to the user. [1] [2]
  • Updated syncDnsRecords in Domain.php to remove internal error catching, allowing exceptions to propagate and be handled at a higher level, improving error visibility and rollback behavior. [1] [2]
  • Improved error handling in controller actions (DNSRecordController.php), so that sync failures return user-friendly error messages and appropriate HTTP status codes. [1] [2]
CleanShot 2026-03-16 at 17 10 20

DNS provider error propagation:

  • Modified Cloudflare.php to throw exceptions when DNS record fetching fails, rather than silently returning empty results, ensuring that upstream errors are properly handled. [1] [2]

Testing enhancements:

  • Added and updated feature and unit tests to verify that errors during DNS record sync or domain creation are correctly surfaced and that failed operations do not persist data. These tests also check that error messages and validation behaviors are correct. [1] [2] [3] [4] [5]

Test mocking improvements:

  • Updated test mocks to simulate both successful and failing DNS provider API calls, ensuring comprehensive coverage of new error handling code paths. [1] [2]

These changes collectively make domain and DNS record management more robust, user-friendly, and reliable in the face of external provider failures.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR strengthens domain/DNS record workflows by propagating provider errors instead of suppressing them, and by ensuring domain creation is rolled back when initial DNS record sync fails.

Changes:

  • Wrap domain creation + initial DNS record sync in a DB transaction and surface sync failures as validation errors.
  • Let DNS record sync failures bubble up (Domain model + Cloudflare provider), and handle them in web/API controllers with user-facing errors.
  • Update/add feature + unit tests to cover the new failure behaviors.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
app/Actions/Domain/AddDomain.php Wraps domain creation + initial record sync in a DB transaction and converts failures into validation errors.
app/Models/Domain.php Removes internal exception suppression in syncDnsRecords() so callers can handle failures.
app/DNSProviders/Cloudflare.php Throws on getRecords() failure instead of returning an empty record set.
app/Http/Controllers/DNSRecordController.php Catches sync exceptions and flashes an error to the user.
app/Http/Controllers/API/DNSRecordController.php Catches sync exceptions and returns an error JSON response.
tests/Unit/DNSProviders/CloudflareTest.php Updates unit expectations for thrown exceptions from getRecords().
tests/Feature/DomainsTest.php Adds coverage for sync/create failure flows in the web UI.
tests/Feature/API/DomainsTest.php Adds coverage for create-domain rollback behavior in the API.
tests/Feature/API/DNSRecordTest.php Adds coverage for API sync error response when provider fails.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@saeedvaziry saeedvaziry merged commit 05686b0 into vitodeploy:3.x Mar 16, 2026
3 checks passed
RichardAnderson added a commit to RichardAnderson/vito that referenced this pull request Mar 16, 2026
* throw error instead of suppressing

* Add error message from generic error

* fixes

* fix naming issue

align with interface
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.

3 participants