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

[update] add on error handlers for jquery ajax events #186

Merged
merged 1 commit into from
Feb 22, 2016

Conversation

kelvintaywl
Copy link
Contributor

This is just an attempt to add some handling on when the ajax requests fail.

@patatepartie
Copy link

What about using a global error handler, instead of duplicating this code ?
https://api.jquery.com/ajaxerror/

@kelvintaywl kelvintaywl force-pushed the update-add-error-function-when-ajax-fail branch from 3c519ff to 17f6a5d Compare February 22, 2016 07:20
@kelvintaywl
Copy link
Contributor Author

@patatepartie ah, thanks for the suggestion. I tried with a sample fiddle here @ https://jsfiddle.net/16ccx3uf/. seems good as we can still have custom error handlers in specific ajax calls while having the global error handler executed as well :) updated the code as such.

@@ -8,6 +8,12 @@
}
};

// register common error handler on Ajax errors / failures
function logError(err) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can inline this method, since it's not used anywhere else.
If you think the logError name is useful, you can write:

$(document).ajaxError(function logError(err) {
  console.error(err)
});

Otherwise, this is enough:

$(document).ajaxError(console.error);

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$(document).ajaxError(console.error);

Seems good for now 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought of that as well initially as well, but decided against it somehow (based on second-guessing myself). will do so!

@kelvintaywl kelvintaywl force-pushed the update-add-error-function-when-ajax-fail branch from 17f6a5d to b46a558 Compare February 22, 2016 08:02
@marexandre
Copy link
Contributor

LGTM 🎉

@patatepartie
Copy link

LGTM, thanks @kelvintaywl

kelvintaywl added a commit that referenced this pull request Feb 22, 2016
…x-fail

[update] add on error handlers for jquery ajax events
@kelvintaywl kelvintaywl merged commit e2ff3f1 into master Feb 22, 2016
@kelvintaywl kelvintaywl deleted the update-add-error-function-when-ajax-fail branch February 22, 2016 08:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants