Open djskimo opened 11 years ago
if you can provide a code example it would make it easier for me to fix this for you. sorry for the long delay
Hi,
Thanks for follow-up. I managed to get a friend to look at the issue and fix. I will try my best to place here what the issue was. Sorry I am not a developer by trade so hope I manage to get this across correctly.
**Example Problem:
client.login({ className : 'deejay', 'username' : emailValue, 'password' : djpasswordField.value, headers : { 'Accept': 'application/vnd.stackmob+json; version=0', 'X-StackMob-API-Key-3619de66-7732-4cab-84b8-50682e75959a':'1',
},
success : function(data) {
//stuff here works on success
},
error: function(data){
//this function never fires even on errors
},
});
*****The fix was in this file: jsOAuth-1.3.1.min.js
****The fixed code: xhr.onreadystatechange = function () { if (xhr.readyState === 4) { var regex = /^(.?):\s(.?)\r?$/mg, requestHeaders = headers, responseHeaders = {}, responseHeadersString = '', match;
if (!!xhr.getAllResponseHeaders) {
responseHeadersString = xhr.getAllResponseHeaders();
while((match = regex.exec(responseHeadersString))) {
responseHeaders[match[1]] = match[2];
}
} else if(!!xhr.getResponseHeaders) {
responseHeadersString = xhr.getResponseHeaders();
for (var i = 0, len = responseHeadersString.length; i < len; ++i) {
responseHeaders[responseHeadersString[i][0]] = responseHeadersString[i][1];
}
}
var responseObject = {text: xhr.responseText, requestHeaders: requestHeaders, responseHeaders: responseHeaders};
// we are powerless against 3xx redirects
if((xhr.status >= 200 && xhr.status <= 226) || xhr.status == 304 || xhr.status === 0) {
success(responseObject);
// everything what is 400 and above is a failure code
} else if(xhr.status >= 400 && xhr.status !== 0) {
failure(responseObject);
}
}
};
// THIS IS THE ADDITION xhr.onerror = function() { var responseObject = {text: this.responseText}; failure(responseObject); }
Hope this helps! Thanks again for making this module avalable!
Hello,
Been using this module for a year. I noticed when doing a client.login to login user to stackmob, the "success" callback works, but not the "error". As such, I am unable to detect bad username password. The issue is also there for the client.create (signup a user).
Greatly appreciated if this could be fixed. I a have been fiddling with this for days now but unfortunately my JS knowledge is extremely limited. Thanks!