typescriptabp-frameworktoastr

How to prevent duplicates abp.notify.warn toastr?


I have been trying to prevent the same warning message from appearing. multiple duplicate warning popup But I don't want to stop duplicate for every popup. Only for one of them.

CageAuto.ts

getMeasure(): IMeasurement {
    [...]
    if (heightPos <= 1) {
       throw new Error("Posterior Height is less than or equal to 1mm");
    }
    [...]
}

toolBase.ts

updateMeasures(): void {
    try {
        this.measurement = this.getMeasure();
    } catch (e) {
        abp.notify.warn(e, '', { preventDuplicates: true, timeOut: 1000 });
        return;
    }
}

I uses the ABP Framework : ABP warn. It uses the library Toastr : toastr github.
The option

preventDuplicates: true

does not work, and I don't know why. However, the other option

timeOut: 1000

is working fine.

What am i missing? What did i do wrong?

Thanks


Solution

  • According to our discussion, you have to pass a string in the first parameter of warn. In the classic Error object, you can use the message property. Like this:

    updateMeasures(): void {
        try {
            this.measurement = this.getMeasure();
        } catch (e) {
            abp.notify.warn(e.message, '', { preventDuplicates: true, timeOut: 1000 });
            return;
        }
    }
    

    Since the value e in the catch is not necessary an error object, you can check if message is defined and pass a default error message like this:

    abp.notify.warn(e.message ?? 'Default error message', '', { preventDuplicates: true, timeOut: 1000 });