Fix parsing rare GFE status code of 0xFFFFFFFF

This commit is contained in:
Cameron Gutman 2020-04-23 18:47:01 -07:00
parent c30c54d562
commit 20dc351f4c

View File

@ -186,22 +186,15 @@ public class NvHTTP {
}
private static void verifyResponseStatus(XmlPullParser xpp) throws GfeHttpResponseException {
String statusCodeText = xpp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "status_code");
if (statusCodeText == null) {
throw new GfeHttpResponseException(418, "Status code is missing");
}
try {
int statusCode = Integer.parseInt(statusCodeText);
// We use Long.parseLong() because in rare cases GFE can send back a status code of
// 0xFFFFFFFF, which will cause Integer.parseInt() to throw a NumberFormatException due
// to exceeding Integer.MAX_VALUE. We'll get the desired error code of -1 by just casting
// the resulting long into an int.
int statusCode = (int)Long.parseLong(xpp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "status_code"));
if (statusCode != 200) {
throw new GfeHttpResponseException(statusCode, xpp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "status_message"));
}
}
catch (NumberFormatException e) {
// It seems like GFE 3.20.3.63 is returning garbage for status_code in rare cases.
// Surface this in a more friendly way rather than crashing.
throw new GfeHttpResponseException(418, "Status code is not a number: "+statusCodeText);
}
}
public String getServerInfo() throws IOException, XmlPullParserException {
String resp;