Frankenmint Frankenmint - 1 year ago 917
Javascript Question

Uncaught (in promise) cancel using SweetAlert2

how do I properly escape the cancel button without throwing an error when using promises? My code throws an alert confirmation with a required checkbox. the code executes as it should to the user, but it throws an error in the console window:

Uncaught (in promise) cancel

//validation logic all passes...Now proceed to...


//determine and parse Discounts

var myLookup = document.getElementsByName("myLookup")[0].value;
$.post( "findthem.php", {myLookup: myLookup })
var theResponse1 = $.parseJSON(json_data);
myDiscountRate = theResponse1['ourDiscountFound'];

}).then( function(callback){

priceRate = priceRate * (1 - (.01 * myDiscountRate));
newRate = priceRate.toFixed(2);

title: "Confirm",
input: 'checkbox',
inputValue: 0,
type: "warning",
inputPlaceholder: 'I agree to <a href="#blahblahMore"></a> Your new Rate is :'+newRate,
showCancelButton: true,
confirmButtonText: 'Confirm',
showLoaderOnConfirm: true,
preConfirm: function(result) {
return new Promise(function(resolve, reject) {
if (result) {
$.post("my.php", {
Data: data
function(json_data) {
var data_array = $.parseJSON(json_data);
var moreDetails = '';
var resulting = 'error';
var details = "Transaction Declined"
if (data_array["trxApproved"] == true) {
resulting = 'success';
details = "Confirmed"
moreDetails = "<br>Approved<b>" + data_array["approved"] + "</b>" +
"<br>Details Code: <b>" + data_array["detailsCode"] + "</b>";
type: resulting,
title: details,
html: "<h1>Details: </h1>" + data_array["messagetext"] + moreDetails
} else {
reject('You must agree to our Terms & Conditions ');
allowOutsideClick: false
}).then(function(json_data) {


Answer Source

You need to add a rejection handler to the Promise. Alternatively, SweetAlert2 provides the .done() method as a quick way to simply suppress the errors:


This issue is mentioned in the package documentation:

Also, there's the closed issue about the subject: limonte/sweetalert2#221

PS. the package you're using is called sweetalert2, not sweetalert. In future questions please mention it so you can get more relevant answers.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download