-
FEATURED COMPONENTS
First time here? Check out the FAQ!
1 | initial version | |
Hi Aaron,
always nice hearing from you :)
As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61
The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248
This method cannot be overridden easily as it's not public and patching the .js file would be necessary.
The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).
On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.
To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:
zk.afterLoad(function() {
var origEvalJSON = jq.evalJSON;
jq.evalJSON = function(jsonResponse) {
try {
origEvalJSON.apply(this, arguments);
} catch (e) {
//your code here to display the problematic text
console.log('Error parsing JSON response:', e);
console.log(jsonResponse);
throw e;
}
};
});
Robert
2 | No.2 Revision |
Hi Aaron,
always nice hearing from you :)
As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61
The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248
This method cannot be overridden easily as it's not public and patching the .js file would be necessary.
The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).
On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.
To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:
zk.afterLoad(function() {
var origEvalJSON = jq.evalJSON;
jq.evalJSON = function(jsonResponse) {
try {
return origEvalJSON.apply(this, arguments);
} catch (e) {
//your code here to display the problematic text
console.log('Error parsing JSON response:', e);
console.log(jsonResponse);
throw e;
}
};
});
Robert
3 | No.3 Revision |
Hi Aaron,
always nice hearing from you :)
As you mentioned the error happens when trying to parse the response into a JSON object. https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L179 and https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L61
The exception is handled in the catch block of onResponseReady: https://github.com/zkoss/zk/blob/8d4561145acd5f950a3adaac900c7b26ce461b37/zk/src/archive/web/js/zk/au.js#L248
This method cannot be overridden easily as it's not public and patching the .js file would be necessary.
The error message may be misleading in particular cases. It is most often caused by an incorrect redirect to a login or error page (which happens when the server has some kind of problem or is configured incorrectly and does not respond to the ajax request in a way the client side expects).
On the client side there is no way to find out what causes the redirect as it's handled transparently by the XMLHttpRequest.
To output the failed JSON string (e.g. an HTML document) the jq.evalJSON function can be overridden like this:
zk.afterLoad(function() {
var origEvalJSON = jq.evalJSON;
jq.evalJSON = function(jsonResponse) {
try {
return origEvalJSON.apply(this, arguments);
} catch (e) {
//your code here to display the problematic text
console.log('Error parsing JSON response:', e);
console.log(jsonResponse);
throw e;
}
};
});
Robert