Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

User can't specify own error handling logic #2503

Closed
VilleSalonen opened this Issue · 8 comments

3 participants

@VilleSalonen

If there's an error when loading a page, just the page loading error message is shown. For example I'm working on a site where user has to be authenticated to access pages and if the authentication session dies between page loads, user just gets the basic error loading message.

I'm proposing adding a new setting with which developer can specify her own error handling function which can for example show different error message based on the error type or redirect the user to login page.

@VilleSalonen

Added pull request for this issue: #2504

@jblas

@VillSalonen

I was actually going to add pagebeforeload, pageload, and pageloadfailed event triggers so folks could get notifications. I can make the pageloadfailed an event that you can call preventDefault() on to cancel the default behavior and indicate that you have handled it.

Doing it in this manner allows folks to register multiple handlers for debugging purposes, and still be able to have their own error/page handlers in place.

@VilleSalonen

That sounds even better than my implementation. Any idea how soon this change would land the stable release?

@jblas

@VilleSalonen

I'll try to land something today.

@jblas jblas was assigned
@jblas

Fix landed on the HEAD:

4f066b7

I'll be checking in the docs for the notifications soon.

@VilleSalonen

Note that when you preventDefault() on the pageloadfailed event, you need to make sure you call resolve/reject on the deferred object so that the framework can continue on it's normal flow. Example:

$( document ).bind( "pageloadfailed", function( event, data ) {
    // Do what you want.

    data.deferred.reject();
};

The reason I don't handle that for you is because the developer may want to load something else when they get a failure, in which case they would call data.deferred.resolve(data.absUrl, data.options) to signal success instead of a fail.

@jblas jblas closed this
@hotTea

@jblas

Your solution is awesome. I was wondering if there was any issue passing the xhr object as well with the data when the "pageloadfailed" event is triggered. for eg. triggerData.xhr = xhr; This would allow developers to work with the response returned from the server. Or is that data already available to devs through some other mechanism ? Thanks. Since this is an inquiry, I didn't open a new bug and thought it would be appropriate to ask here.

@jblas jblas referenced this issue from a commit
@jblas jblas Add the XHR object to the data passed to loadpage and loadpagefailed …
…callbacks. This was a low-hanging-fruit enhancement request for issue #2503 - User can't specify own error handling logic.
1405a94
@jblas

@hotTea

I just landed your request on the HEAD. It will appear in 1.0 final.

@hotTea

@jblas Awesome ! Thanks !!

@timmywil timmywil referenced this issue from a commit in timmywil/jquery-mobile
@jblas jblas Add the XHR object to the data passed to loadpage and loadpagefailed …
…callbacks. This was a low-hanging-fruit enhancement request for issue #2503 - User can't specify own error handling logic.
228760f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.