Skip to content

Instantly share code, notes, and snippets.

@house9
Created August 21, 2009 19:21
Show Gist options
  • Save house9/172345 to your computer and use it in GitHub Desktop.
Save house9/172345 to your computer and use it in GitHub Desktop.
function defaultAjaxErrorHandler(result, isAjaxError) {
// do stuff, hide spinner etc...
var defaultAjaxError = "Your friendly error message";
var errorToken = "Error:";
if(!isUndefinedOrNull(result) && !isUndefinedOrNull(result.responseText)) {
if(result.responseText.startsWith(errorToken)) {
// localhost
var x = (result.responseText.length > 350) ? 350 : result.responseText.length;
alert(result.responseText.substring(0, x) + "...\n\n - Check firebug console for more info.\n - This message for localhost only.");
}
else {
// production error
alert(defaultAjaxError);
}
}
else {
// production error
alert(defaultAjaxError);
}
}
function isUndefinedOrNull(x) {
var u; // undefined var
if(x === u) { // similar to [typeof x == "undefined"]
return true;
}
// else
return x === null;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment