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
[TIMOB-25241] Android: Do not throw exception on HTTP 400 codes #9411
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@garymathews, HTTP responses having status codes >= 400 are supposed to invoke the onerror() listener. This is how we document it (link below) and how it works on iOS (see iOS log output in JIRA case).
http://docs.appcelerator.com/platform/latest/#!/api/Titanium.Network.HTTPClient-property-onerror
So, we may want to do the following in the Java setReadyState() method...
public void setReadyState(int readyState)
{
Log.d(TAG, "Setting ready state to " + readyState, Log.DEBUG_MODE);
this.readyState = readyState;
KrollDict data = new KrollDict();
data.put("readyState", Integer.valueOf(readyState));
dispatchCallback(TiC.PROPERTY_ONREADYSTATECHANGE, data);
if (readyState == READY_STATE_DONE) {
KrollDict data1 = new KrollDict();
if (getStatus() >= 400) {
if (getStatusText == null) {
setStatusText("");
}
data1.putCodeAndMessage(getStatus(), getStatus() + " : " + getStatusText());
dispatchCallback(TiC.PROPERTY_ONERROR, data1);
} else {
data1.putCodeAndMessage(TiC.ERROR_CODE_NO_ERROR, null);
dispatchCallback(TiC.PROPERTY_ONLOAD, data1);
}
}
}
Personally, I would prefer onload to be invoked for HTTP errors responses too (like you're doing it) and only invoke onerror for socket errors, timeouts, and SSL errors... but that's not how it's documented/designed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CR: Pass
Tests:
Generated by 🚫 dangerJS |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Passed FR with this environment:
Node Version: 6.11.5
NPM Version: 3.10.10
Mac OS: 10.13
Appc CLI: 7.0.0-master.8
Appc CLI NPM: 4.2.11-2
Titanium SDK version: 7.0.0 locally built
Appcelerator Studio vers 4.10.0
Android 7.1.2
TEST CASE
JIRA Ticket