🩹 ConsoleLogger will always output error messages

This commit is contained in:
Philipp Stracker 2024-08-07 14:36:51 +02:00
parent 31867b17d6
commit 4b30449ddb
No known key found for this signature in database
2 changed files with 20 additions and 5 deletions

View file

@ -227,8 +227,8 @@ class GooglepayButton extends PaymentButton {
this.paymentsClient.loadPaymentData( paymentDataRequest );
},
() => {
console.error( '[GooglePayButton] Form validation failed.' );
( reason ) => {
this.error( 'Form validation failed.', reason );
}
);
}

View file

@ -24,10 +24,20 @@ export default class ConsoleLogger {
}
}
/**
* Enable or disable logging. Only impacts `log()` output.
*
* @param {boolean} state True to enable log output.
*/
set enabled( state ) {
this.#enabled = state;
}
/**
* Output log-level details to the browser console, if logging is enabled.
*
* @param {...any} args - All provided values are output to the browser console.
*/
log( ...args ) {
if ( this.#enabled ) {
// eslint-disable-next-line
@ -35,9 +45,14 @@ export default class ConsoleLogger {
}
}
/**
* Generate an error message in the browser's console.
*
* Error messages are always output, even when logging is disabled.
*
* @param {...any} args - All provided values are output to the browser console.
*/
error( ...args ) {
if ( this.#enabled ) {
console.error( this.#prefix, ...args );
}
}
}