User can't specify own error handling logic #2503

Closed
VilleSalonen opened this Issue Sep 22, 2011 · 8 comments

Comments

Projects
None yet
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

This comment has been minimized.

Show comment
Hide comment
@VilleSalonen

VilleSalonen Sep 22, 2011

Added pull request for this issue: #2504

Added pull request for this issue: #2504

@jblas

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Sep 22, 2011

Contributor

@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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@VilleSalonen

VilleSalonen Sep 22, 2011

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

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

@jblas

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Sep 22, 2011

Contributor

@VilleSalonen

I'll try to land something today.

Contributor

jblas commented Sep 22, 2011

@VilleSalonen

I'll try to land something today.

@ghost ghost assigned jblas Sep 22, 2011

@jblas

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Sep 23, 2011

Contributor

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.

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@hotTea

hotTea 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.

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

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.
@jblas

This comment has been minimized.

Show comment
Hide comment
@jblas

jblas Oct 26, 2011

Contributor

@hotTea

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

Contributor

jblas commented Oct 26, 2011

@hotTea

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

@hotTea

This comment has been minimized.

Show comment
Hide comment
@hotTea

hotTea Oct 26, 2011

@jblas Awesome ! Thanks !!

hotTea commented Oct 26, 2011

@jblas Awesome ! Thanks !!

timmywil pushed a commit to timmywil/jquery-mobile that referenced this issue Nov 5, 2011

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment