mirror of
https://github.com/moonlight-stream/moonlight-android.git
synced 2025-07-21 03:52:48 +00:00
Throw a GfeHttpResponseException if an HTTP response has an error code
This commit is contained in:
parent
616945a963
commit
ade061bf3c
@ -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+")";
|
||||
}
|
||||
}
|
@ -42,6 +42,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());
|
||||
break;
|
||||
case (XmlPullParser.END_TAG):
|
||||
@ -59,6 +62,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();
|
||||
conn.setConnectTimeout(CONNECTION_TIMEOUT);
|
||||
@ -102,7 +112,7 @@ public class NvHTTP {
|
||||
return null;
|
||||
}
|
||||
|
||||
public LinkedList<NvApp> getAppList() throws IOException, XmlPullParserException {
|
||||
public LinkedList<NvApp> 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());
|
||||
|
Loading…
x
Reference in New Issue
Block a user