winter icon indicating copy to clipboard operation
winter copied to clipboard

Errors in beforeDelete are not shown to the user

Open multiwebinc opened this issue 3 years ago • 7 comments

Winter CMS Build

1.2

PHP Version

8.1

Database engine

SQLite

Plugins installed

No response

Issue description

When saving a model, the following code causes the error message to be displayed to the user:

public function beforeSave() 
{
    throw new \Winter\Storm\Exception\ApplicationException('Unable to save');
}

However when deleting the model, the following code does not display the error to the user:

public function beforeDelete()
{
    if (!empty($this->categories)) {
        throw new \Winter\Storm\Exception\ApplicationException('Unable to delete');
    }
}

The request responses appear to be the same (i.e. both return 500 status code and just the error message string), so I would assume the bug lies somewhere in the client-side code.

Steps to replicate

(see description)

Workaround

No response

multiwebinc avatar Jan 20 '23 23:01 multiwebinc

The error is because swal is used for both $.wn.alert() as well as $.wn.confirm. It is trying to display an alert before SweetAlert has finished closing.

multiwebinc avatar Jan 21 '23 00:01 multiwebinc

https://github.com/wintercms/winter/blob/68b9a55abd8d9cb886ac3f5101c9a91821751e7a/modules/backend/assets/js/winter.alert.js#L21-L36

multiwebinc avatar Jan 21 '23 02:01 multiwebinc

@multiwebinc thanks for the report. Confirmed the issue - will try and investigate a fix.

bennothommo avatar Jan 23 '23 08:01 bennothommo

@bennothommo Maybe upgrading to SweetAlert 2 would be an option since it is promise-based. They even have an ajax request example in the docs.

multiwebinc avatar Jan 23 '23 21:01 multiwebinc

@bennothommo any updates?

LukeTowers avatar Apr 25 '24 23:04 LukeTowers

Not at this stage.

bennothommo avatar Apr 26 '24 01:04 bennothommo

Open for anyone who wants to submit a PR to fix it if they want it fixed; otherwise I'll just let the bot close it next time it comes up.

LukeTowers avatar Apr 26 '24 03:04 LukeTowers