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

Question / Feature request: Global event handler for failed requests #2660

Closed
mozan opened this issue Sep 17, 2018 · 4 comments
Closed

Question / Feature request: Global event handler for failed requests #2660

mozan opened this issue Sep 17, 2018 · 4 comments

Comments

@mozan
Copy link
Contributor

mozan commented Sep 17, 2018

What do I exactly need is a handler which would be executed (if set of course) when an ajax request failed. Basically I'd like to be able to modify the behavior of "request()->error()" javascript function.

What more - in the handler, I'd like to have an option to cancel further processing of original error() .

Why? Because right now, when the session of my app expires, and let's say I try to create a new folder - I get an ugly response ("Data is not JSON...." with the source of login page).

Having proposed handler I could easily redirect to login page.

I think such a functionality could also be useful for done() and success().

PS. Of course globally for every command.
PS2. The handler should accept as a parameter the command name from which it was invoked and the final URL after an Ajax redirect (if there was one).

@nao-pon
Copy link
Member

nao-pon commented Sep 20, 2018

@mozan I added an event requestError to fix this issue. see 81ba8a4. Thanks! 👍

@mozan
Copy link
Contributor Author

mozan commented Sep 20, 2018

@nao-pon It's a pleasure working with You. Nice and clean, works perfectly :)

Just one more question. I'm not quite sure (to be honest - I have no idea) how to display a modal dialog, with just a simple info, that the session timed out.

This is what I did. It works - almost... The dialog is not modal:(

if (loc) {
	fm.error(["Your session expired. You'll be redirected to the login page.", ''], {modal: true});

	// prevent showing error messages
	e.preventDefault();
	window.location = loc;
}

@nao-pon
Copy link
Member

nao-pon commented Sep 21, 2018

@mozan Please use an option close.

if (loc) {
    // prevent showing error messages
    e.preventDefault();
    fm.error('Your session expired. You\'ll be redirected to the login page.', {
        modal: true,
        close: function() {
            window.location = loc;
        }
    });
}

@nao-pon nao-pon added the howto label Sep 21, 2018
@mozan
Copy link
Contributor Author

mozan commented Sep 21, 2018

@nao-pon Exactly what I needed. Thank you!

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

2 participants