diff --git a/app/src/main/java/com/limelight/nvstream/http/NvHTTP.java b/app/src/main/java/com/limelight/nvstream/http/NvHTTP.java index c4d2332f..9729b9c5 100644 --- a/app/src/main/java/com/limelight/nvstream/http/NvHTTP.java +++ b/app/src/main/java/com/limelight/nvstream/http/NvHTTP.java @@ -186,20 +186,13 @@ 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); - 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); + // 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")); } }