mirror of
https://github.com/woocommerce/woocommerce-paypal-payments.git
synced 2025-09-01 07:02:48 +08:00
✨ New ConsoleLogger group
method
Groups subsequent console.log output, for cleaner console output
This commit is contained in:
parent
00e2959700
commit
63e9c8bf27
3 changed files with 49 additions and 7 deletions
|
@ -599,6 +599,15 @@ export default class PaymentButton {
|
||||||
this.#logger.error( ...args );
|
this.#logger.error( ...args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Open or close a log-group
|
||||||
|
*
|
||||||
|
* @param {?string} [label=null] Group label.
|
||||||
|
*/
|
||||||
|
logGroup( label = null ) {
|
||||||
|
this.#logger.group( label );
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Determines if the current button instance has valid and complete configuration details.
|
* Determines if the current button instance has valid and complete configuration details.
|
||||||
* Used during initialization to decide if the button can be initialized or should be skipped.
|
* Used during initialization to decide if the button can be initialized or should be skipped.
|
||||||
|
|
|
@ -560,7 +560,7 @@ class GooglepayButton extends PaymentButton {
|
||||||
}
|
}
|
||||||
|
|
||||||
async processPayment( paymentData ) {
|
async processPayment( paymentData ) {
|
||||||
this.log( 'processPayment' );
|
this.logGroup( 'processPayment' );
|
||||||
|
|
||||||
const paymentError = ( reason ) => {
|
const paymentError = ( reason ) => {
|
||||||
this.error( reason );
|
this.error( reason );
|
||||||
|
@ -623,13 +623,13 @@ class GooglepayButton extends PaymentButton {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const success = await approveOrderServerSide( id );
|
const success = await approveOrderServerSide( id );
|
||||||
|
|
||||||
if ( success ) {
|
if ( success ) {
|
||||||
resolve( this.processPaymentResponse( 'SUCCESS' ) );
|
resolve( this.processPaymentResponse( 'SUCCESS' ) );
|
||||||
} else {
|
} else {
|
||||||
resolve( paymentError( 'FAILED TO APPROVE' ) );
|
resolve( paymentError( 'FAILED TO APPROVE' ) );
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const propagatePayerDataToForm = () => {
|
const propagatePayerDataToForm = () => {
|
||||||
|
@ -660,6 +660,8 @@ class GooglepayButton extends PaymentButton {
|
||||||
} catch ( err ) {
|
} catch ( err ) {
|
||||||
resolve( paymentError( err.message ) );
|
resolve( paymentError( err.message ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.logGroup();
|
||||||
} );
|
} );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -18,6 +18,13 @@ export default class ConsoleLogger {
|
||||||
*/
|
*/
|
||||||
#enabled = false;
|
#enabled = false;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tracks the current log-group that was started using `this.group()`
|
||||||
|
*
|
||||||
|
* @type {?string}
|
||||||
|
*/
|
||||||
|
#openGroup = null;
|
||||||
|
|
||||||
constructor( ...prefixes ) {
|
constructor( ...prefixes ) {
|
||||||
if ( prefixes.length ) {
|
if ( prefixes.length ) {
|
||||||
this.#prefix = `[${ prefixes.join( ' | ' ) }]`;
|
this.#prefix = `[${ prefixes.join( ' | ' ) }]`;
|
||||||
|
@ -55,4 +62,28 @@ export default class ConsoleLogger {
|
||||||
error( ...args ) {
|
error( ...args ) {
|
||||||
console.error( this.#prefix, ...args );
|
console.error( this.#prefix, ...args );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Starts or ends a group in the browser console.
|
||||||
|
*
|
||||||
|
* @param {string} [label=null] - The group label. Omit to end the current group.
|
||||||
|
*/
|
||||||
|
group( label = null ) {
|
||||||
|
if ( ! this.#enabled ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( ! label || this.#openGroup ) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.groupEnd();
|
||||||
|
this.#openGroup = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( label ) {
|
||||||
|
// eslint-disable-next-line
|
||||||
|
console.group( label );
|
||||||
|
|
||||||
|
this.#openGroup = label;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue