added
You get error message ONLY when this
is undefined - not when this is re-scoped to different object. For your toast to work correctly this
should refer to class HoldModal
as toast should be invoked on instance of the class and not on any other element.
Although you are trying to save the scope of this
by using const thisReference = this;, the scope of this
has already changed because it has been invoked from catch block. The simplest way to fix the issue is using arrow function - does not have own scope so the scope of this
is always intact.
fetch(url, params)
.then((response) => response.json())
.then((data) => {
if (data.message) {
// handle later
}
else if (data.errors) {
this.doDisplayToastMsg('error','within fetch',this.msgToDisplay);
}
})
.then(() => {
// logic
})
.catch((error) => {
console.log('doReleaseHoldRequest error: ' + error);
})