woocommerce-paypal-payments/modules.local/ppcp-button/resources/js/modules/ErrorHandler.js
Mészáros Róbert cfe450f835 Pass the error message from the api up to the button's error handler
Remove the "Error:" prefix front he front-end facing error message

The notice has already the error state and it's implied
2020-04-23 17:13:12 +03:00

31 lines
709 B
JavaScript

class ErrorHandler {
constructor()
{
this.wrapper = document.querySelector('.woocommerce-notices-wrapper');
}
message(text)
{
this.wrapper.classList.add('woocommerce-error');
this.wrapper.innerText = this.sanitize(text);
}
sanitize(text)
{
const textarea = document.createElement('textarea');
textarea.innerHTML = text;
return textarea.value.replace('Error: ', '');
}
clear()
{
if (! this.wrapper.classList.contains('woocommerce-error')) {
return;
}
this.wrapper.classList.remove('woocommerce-error');
this.wrapper.innerText = '';
}
}
export default ErrorHandler;