Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errors in beforeDelete are not shown to the user #822

Open
multiwebinc opened this issue Jan 20, 2023 · 7 comments
Open

Errors in beforeDelete are not shown to the user #822

multiwebinc opened this issue Jan 20, 2023 · 7 comments
Assignees
Milestone

Comments

@multiwebinc
Copy link
Contributor

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
Copy link
Contributor Author

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
Copy link
Contributor Author

$.wn.alert = function alert(message) {
swal({
title: message,
confirmButtonClass: 'btn-primary'
})
}
$.wn.confirm = function confirm(message, callback) {
swal({
title: message,
showCancelButton: true,
confirmButtonClass: 'btn-primary'
}, callback)
}

@bennothommo
Copy link
Member

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

@multiwebinc
Copy link
Contributor Author

@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 bennothommo modified the milestones: v1.2.2, v1.2.3 Apr 30, 2023
@LukeTowers LukeTowers modified the milestones: v1.2.3, v1.2.4 Jul 7, 2023
@LukeTowers LukeTowers modified the milestones: v1.2.4, 1.2.5 Dec 27, 2023
@mjauvin mjauvin modified the milestones: 1.2.5, 1.2.6 Feb 18, 2024
@LukeTowers
Copy link
Member

@bennothommo any updates?

@LukeTowers LukeTowers modified the milestones: 1.2.6, 1.2.7 Apr 25, 2024
@bennothommo
Copy link
Member

Not at this stage.

@LukeTowers
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants