I do some asynchronous REST API calls in my JS:
async function api(args)
{
var response = await $.post( "/api", args)
.fail(function(xhr, status, error)
{
console.log(xhr);
console.log(status);
console.log(error);
errorLog(".fail in api: " + status + " - " + error + " - " + xhr.status + " - " + xhr.statusText + " - " + xhr.responseText);
});
}
In case something is wrong, I want to log out the root cause. I tried so many things, but it is impossible to log out the error reason. The only thing I have in my log files is:
Object {
readyState: 0, getResponseHeader: getResponseHeader(key), getAllResponseHeaders: getAllResponseHeaders(),
setRequestHeader: setRequestHeader(name, value),
overrideMimeType: overrideMimeType(type), statusCode:
statusCode(map), abort: abort(statusText), state:
state(), always: always(), catch: catch(fn), … }
.fail in api: error - - 0 - error - undefined
What I am doing wrong? Is this maybe because its inside an async method? Nothing explains me the actual root cause, I only get "error", "undefinied", "0" and " ".
Additional Info: I have that code online, it only happens for Firefox users (I log out the browser engine, its always "Mozilla/5.0")