0

I am not a JavaScript guy (can only write simple JS function), I am trying to debug a code with the JS where my backed system is passing the correct values but I am getting an error while processing the code on the UI. Here is the JS code

this.session.onvalidatemerchant = function (event) {
    this.performAuthorizeMerchantRequest(event.validationURL)
        .then(function (merchantSession) {
            this.session.completeMerchantValidation(merchantSession);
            alert("jdshhdjhjdhh");
        }.bind(this))
        .catch(this.showPaymentError.bind(this));
}.bind(this);

Here is the error handling function

showPaymentError: function () {
  //showing a message on the UI
}

I have already verified the data being passed from my backed service is correct, I don't see the following alter alert("jdshhdjhjdhh");. There seems to be issue with the completeMerchantValidation method but I am not sure what is the root cause for failure.I tried to change my error message with something like this

showPaymentError: function (e) {
    console.log("*****111"+e)
}

but getitng the following output in the console *****111TypeError: Type error. Is there a way I can print the error from the completeMerchantValidation. Even tried to add try and catch around that method call but getting js compilation error

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
  • The root cause is a TypeError that is being thrown at some point in the Promise's lifecycle. There is an implicit toString being called on the error object when you append it to "*****111." – user2977636 Feb 19 '21 at 23:38
  • is there a way I can get more error details from this? – Umesh Awasthi Feb 19 '21 at 23:44
  • I added the data in my answer below. It depends on the error object being thrown. I'm not sure how it is implemented. Here is a post for reference: https://stackoverflow.com/questions/591857/how-can-i-get-a-javascript-stack-trace-when-i-throw-an-exception – user2977636 Feb 19 '21 at 23:45

2 Answers2

0

Try this. the try catch will handle the potential error which come from performAuthorizeMerchantRequest or completeMerchantValidation.

this.session.onvalidatemerchant = async ({ validationURL }) => {
  try {
    const merchantSession = await this.performAuthorizeMerchantRequest(validationURL)
    this.session.completeMerchantValidation(merchantSession)
    alert('jdshhdjhjdhh')
  } catch (error) {
    console.error('Oh oh, an error happened', error)
    this.showPaymentError(error);
  }
}
0

The root cause is a TypeError that is being thrown at some point in the Promise's lifecycle.

Given that console.log("*****111"+e) prints *****111TypeError: Type error, we are dealing with a TypeError.

Unfortunately "Type error" isn't the most useful debugging data :(

Maybe try printing the stacktrace?

https://developer.mozilla.org/en-US/docs/Web/API/Console/trace

user2977636
  • 2,086
  • 2
  • 17
  • 21