♻️ Minor code improvement

This commit is contained in:
Philipp Stracker 2024-11-21 19:08:50 +01:00
parent 2a28f38491
commit 88f2ed9185
No known key found for this signature in database

View file

@ -7,7 +7,7 @@ import { store as noticesStore } from '@wordpress/notices';
import SettingsToggleBlock from '../../../ReusableComponents/SettingsToggleBlock';
import Separator from '../../../ReusableComponents/Separator';
import DataStoreControl from '../../../ReusableComponents/DataStoreControl';
import { OnboardingHooks, CommonHooks } from '../../../../data';
import { CommonHooks } from '../../../../data';
const AdvancedOptionsForm = ( { setCompleted } ) => {
const { isBusy } = CommonHooks.useBusyState();
@ -61,17 +61,9 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
return true;
};
const handleServerError = ( res ) => {
if ( res.message ) {
createErrorNotice( res.message );
} else {
createErrorNotice(
__(
'Could not connect to PayPal. Please make sure your Client ID and Secret Key are correct.',
'woocommerce-paypal-payments'
)
);
}
const handleServerError = ( res, genericMessage ) => {
console.error( 'Connection error', res );
createErrorNotice( res?.message ?? genericMessage );
};
const handleServerSuccess = () => {
@ -107,7 +99,13 @@ const AdvancedOptionsForm = ( { setCompleted } ) => {
if ( res.success ) {
handleServerSuccess();
} else {
handleServerError( res );
handleServerError(
res,
__(
'Could not connect to PayPal. Please make sure your Client ID and Secret Key are correct.',
'woocommerce-paypal-payments'
)
);
}
};