Errors in beforeDelete are not shown to the user
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
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.
https://github.com/wintercms/winter/blob/68b9a55abd8d9cb886ac3f5101c9a91821751e7a/modules/backend/assets/js/winter.alert.js#L21-L36
@multiwebinc thanks for the report. Confirmed the issue - will try and investigate a fix.
@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.
@bennothommo any updates?
Not at this stage.
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.