diff --git a/moonlight-common/src/com/limelight/nvstream/http/GfeHttpResponseException.java b/moonlight-common/src/com/limelight/nvstream/http/GfeHttpResponseException.java new file mode 100644 index 00000000..1e5bb878 --- /dev/null +++ b/moonlight-common/src/com/limelight/nvstream/http/GfeHttpResponseException.java @@ -0,0 +1,20 @@ +package com.limelight.nvstream.http; + +import java.io.IOException; + +public class GfeHttpResponseException extends IOException { + private static final long serialVersionUID = 1543508830807804222L; + + private int errorCode; + private String errorMsg; + + public GfeHttpResponseException(int errorCode, String errorMsg) { + this.errorCode = errorCode; + this.errorMsg = errorMsg; + } + + @Override + public String getMessage() { + return "GFE error: "+errorMsg+" (Error code: "+errorCode+")"; + } +} diff --git a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java index 210910c2..8ed565a2 100644 --- a/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java +++ b/moonlight-common/src/com/limelight/nvstream/http/NvHTTP.java @@ -38,10 +38,13 @@ public class NvHTTP { xpp.setInput(new InputStreamReader(in)); int eventType = xpp.getEventType(); Stack currentTag = new Stack(); - + while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case (XmlPullParser.START_TAG): + if (xpp.getName().equals("root")) { + verifyResponseStatus(xpp); + } currentTag.push(xpp.getName()); break; case (XmlPullParser.END_TAG): @@ -58,6 +61,13 @@ public class NvHTTP { return null; } + + private void verifyResponseStatus(XmlPullParser xpp) throws GfeHttpResponseException { + int statusCode = Integer.parseInt(xpp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "status_code")); + if (statusCode != 200) { + throw new GfeHttpResponseException(statusCode, xpp.getAttributeValue(XmlPullParser.NO_NAMESPACE, "status_message")); + } + } private InputStream openHttpConnection(String url) throws IOException { URLConnection conn = new URL(url).openConnection(); @@ -102,7 +112,7 @@ public class NvHTTP { return null; } - public LinkedList getAppList() throws IOException, XmlPullParserException { + public LinkedList getAppList() throws GfeHttpResponseException, IOException, XmlPullParserException { InputStream in = openHttpConnection(baseUrl + "/applist?uniqueid=" + uniqueId); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); factory.setNamespaceAware(true); @@ -116,6 +126,9 @@ public class NvHTTP { while (eventType != XmlPullParser.END_DOCUMENT) { switch (eventType) { case (XmlPullParser.START_TAG): + if (xpp.getName().equals("root")) { + verifyResponseStatus(xpp); + } currentTag.push(xpp.getName()); if (xpp.getName().equals("App")) { appList.addLast(new NvApp());