Skip to content

Commit

Permalink
fix: fetching and display of sync errors after saving
Browse files Browse the repository at this point in the history
  • Loading branch information
dkoo committed Oct 14, 2024
1 parent 0ae5cc5 commit 32a1e88
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1066,7 +1066,7 @@ public function sync( $post ) {
// Retrieve and store campaign data.
$data = $this->retrieve( $post->ID, true );
if ( is_wp_error( $data ) ) {
set_transient( $transient_name, __( 'Error syncing with ESP. ', 'newspack-newsletters' ) . $data->get_error_message(), 45 );
set_transient( $transient_name, __( 'ActiveCampaign sync error: ', 'newspack-newsletters' ) . $data->get_error_message(), 45 );
return $data;
} else {
$data = array_merge( $data, $sync_data );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ public function sync( $post ) {

return $campaign_result;
} catch ( Exception $e ) {
set_transient( $transient_name, __( 'Error syncing with ESP. ', 'newspack-newsletters' ) . $e->getMessage(), 45 );
set_transient( $transient_name, 'Constant Contact campaign sync error: ' . wp_specialchars_decode( $e->getMessage(), ENT_QUOTES ), 45 );
return new WP_Error( 'newspack_newsletters_constant_contact_error', $e->getMessage() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
use Newspack\Newsletters\Send_Lists;
use Newspack\Newsletters\Send_List;

use function cli\err;

/**
* Main Newspack Newsletters Class.
*/
Expand Down Expand Up @@ -1146,13 +1148,11 @@ public function sync( $post ) {

if ( $mc_campaign_id ) {
$campaign_result = $this->validate(
$mc->patch( "campaigns/$mc_campaign_id", $payload ),
__( 'Error updating existing campaign draft.', 'newspack_newsletters' )
$mc->patch( "campaigns/$mc_campaign_id", $payload )
);
} else {
$campaign_result = $this->validate(
$mc->post( 'campaigns', $payload ),
__( 'Error creating campaign.', 'newspack_newsletters' )
$mc->post( 'campaigns', $payload )
);
$mc_campaign_id = $campaign_result['id'];
update_post_meta( $post->ID, 'mc_campaign_id', $mc_campaign_id );
Expand All @@ -1177,7 +1177,7 @@ public function sync( $post ) {
'content_result' => $content_result,
];
} catch ( Exception $e ) {
set_transient( $transient_name, 'Mailchimp: ' . $e->getMessage(), 45 );
set_transient( $transient_name, 'Mailchimp campaign sync error: ' . wp_specialchars_decode( $e->getMessage(), ENT_QUOTES ), 45 );
return new WP_Error( 'newspack_newsletters_mailchimp_error', $e->getMessage() );
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/editor/mjml/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { refreshEmailHtml } from '../../newsletter-editor/utils';
/**
* Internal dependencies
*/
import { fetchNewsletterData, fetchSyncErrors } from '../../newsletter-editor/store';
import { fetchNewsletterData, fetchSyncErrors, updateNewsletterDataError } from '../../newsletter-editor/store';
import { getServiceProvider } from '../../service-providers';

/**
Expand Down Expand Up @@ -105,7 +105,7 @@ function MJML() {
} );
} )
.catch( e => {
console.warn( e ); // eslint-disable-line no-console
updateNewsletterDataError( e );
} )
.finally( () => {
unlockPostSaving( 'newspack-newsletters-refresh-html' );
Expand All @@ -116,10 +116,10 @@ function MJML() {
const isSupportedESP = serviceProviderName && 'manual' !== serviceProviderName && supportedESPs?.includes( serviceProviderName );
if ( isSupportedESP ) {
// Rehydrate ESP newsletter data after completing sync.
fetchNewsletterData( postId );

// Check for sync errors after refreshing the HTML.
fetchSyncErrors( postId );
fetchNewsletterData( postId ).then( () => {
// Check for sync errors after refreshing the HTML.
fetchSyncErrors( postId );
} );
}
} );
}
Expand Down
2 changes: 2 additions & 0 deletions src/newsletter-editor/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ export const fetchNewsletterData = async postId => {
updateNewsletterDataError( error );
}
updateIsRetrieving( false );
return true;
};

// Dispatcher to fetch any errors from the most recent sync attempt.
Expand All @@ -147,6 +148,7 @@ export const fetchSyncErrors = async postId => {
updateNewsletterDataError( error );
}
updateIsRetrieving( false );
return true;
}

// Dispatcher to fetch send lists and sublists from the connected ESP and update the newsletterData in store.
Expand Down

0 comments on commit 32a1e88

Please sign in to comment.