Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: allow for context-specific reader-facing error messsages #1754

Open
wants to merge 4 commits into
base: release
Choose a base branch
from

Conversation

dkoo
Copy link
Contributor

@dkoo dkoo commented Feb 11, 2025

All Submissions:

Changes proposed in this Pull Request:

Builds on filters added in #1745 by allowing reader-facing error messages to be altered depending on the context of the original error thrown by the ESP's API.

This PR adds a special error message for the Mailchimp error that occurs when a contact attempts to resubscribe to a list they've previously unsubscribed from. In all other cases, the error shown will be a generic error: Sorry, an error has occurred. Please try again later or contact us for support.

Also standardizes the error code used across all ESP's when add_contact results in an error to: newspack_{esp}_api_error

How to test the changes in this Pull Request:

set up a contact for the compliance state

  1. Check out this branch.
  2. With Mailchimp enabled, sign up as a reader with a real email address for a test newsletter list/group/tag via any means on the site.
  3. Send a live newsletter campaign to the list/group/tag that the reader will receive.
  4. Once you receive the email in the reader's inbox, click the "Unsubscribe" link at the bottom and confirm.
  5. In a new session, attempt to resubscribe to the same newsletter lists using the same reader email.
  6. Confirm the following error is shown:
Screenshot 2025-02-11 at 4 49 10 PM
  1. Temporarily force an error to occur in the first line of the Mailchimp class validate() method:
	public function validate( $result, $preferred_error = null, $payload = [] ) {
+		$result['status'] = 400;
+		$result['title']  = 'Test error';
+		$result['detail'] = 'Test error message';
		$default_error = $this->get_reader_error_message( $payload, $result );
  1. In a new session, subscribe to a newsletter list with a fresh email address and confirm you get the generic error message:
Screenshot 2025-02-11 at 4 55 17 PM

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

@dkoo dkoo self-assigned this Feb 11, 2025
@dkoo dkoo requested a review from a team as a code owner February 11, 2025 23:55
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

Attention: Patch coverage is 53.12500% with 15 lines in your changes missing coverage. Please review.

Project coverage is 23.31%. Comparing base (69ed769) to head (3d928eb).
Report is 34 commits behind head on release.

Files with missing lines Patch % Lines
...ign/class-newspack-newsletters-active-campaign.php 0.00% 4 Missing ⚠️
...or/class-newspack-newsletters-campaign-monitor.php 0.00% 4 Missing ⚠️
...ct/class-newspack-newsletters-constant-contact.php 0.00% 4 Missing ⚠️
...mailchimp/class-newspack-newsletters-mailchimp.php 81.25% 3 Missing ⚠️
Additional details and impacted files
@@              Coverage Diff              @@
##             release    #1754      +/-   ##
=============================================
+ Coverage      23.29%   23.31%   +0.01%     
- Complexity      2710     2720      +10     
=============================================
  Files             49       49              
  Lines          10754    10853      +99     
=============================================
+ Hits            2505     2530      +25     
- Misses          8249     8323      +74     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant