Skip to content

User can't specify own error handling logic #2503

Closed
VilleSalonen opened this Issue Sep 22, 2011 · 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
jblas commented Sep 22, 2011

@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
jblas commented Sep 22, 2011

@VilleSalonen

I'll try to land something today.

@jblas jblas was assigned Sep 22, 2011
@jblas
jblas commented Sep 23, 2011

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 Sep 23, 2011
@hotTea
hotTea commented Oct 11, 2011

@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 added a commit that referenced this issue Oct 26, 2011
@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
jblas commented Oct 26, 2011

@hotTea

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

@hotTea
hotTea commented Oct 26, 2011

@jblas Awesome ! Thanks !!

@timmywil timmywil pushed a commit to timmywil/jquery-mobile that referenced this issue Nov 5, 2011
@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.