add error handling to suggestions

pull/224/head
Christian Schabesberger 2016-03-01 18:43:36 +01:00
rodzic 1210ab0de0
commit 77b9457707
7 zmienionych plików z 37 dodań i 42 usunięć

Wyświetl plik

@ -76,8 +76,11 @@ public class ErrorActivity extends AppCompatActivity {
public static final String TAG = ErrorActivity.class.toString(); public static final String TAG = ErrorActivity.class.toString();
public static final int SEARCHED = 0; public static final int SEARCHED = 0;
public static final int REQUESTED_STREAM = 1; public static final int REQUESTED_STREAM = 1;
public static final String SEARCHED_STRING = "Searched"; public static final int GET_SUGGESTIONS = 2;
public static final String REQUESTED_STREAM_STRING = "Requested Stream"; public static final String SEARCHED_STRING = "searched";
public static final String REQUESTED_STREAM_STRING = "requested stream";
public static final String GET_SUGGESTIONS_STRING = "get suggestions";
public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org"; public static final String ERROR_EMAIL_ADDRESS = "crashreport@newpipe.schabi.org";
public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME; public static final String ERROR_EMAIL_SUBJECT = "Exception in NewPipe " + BuildConfig.VERSION_NAME;
@ -303,6 +306,8 @@ public class ErrorActivity extends AppCompatActivity {
return REQUESTED_STREAM_STRING; return REQUESTED_STREAM_STRING;
case SEARCHED: case SEARCHED:
return SEARCHED_STRING; return SEARCHED_STRING;
case GET_SUGGESTIONS:
return GET_SUGGESTIONS_STRING;
default: default:
return "Your description is in another castle."; return "Your description is in another castle.";
} }

Wyświetl plik

@ -172,11 +172,17 @@ public class VideoItemListActivity extends AppCompatActivity
ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader()); ArrayList<String>suggestions = engine.suggestionList(query,searchLanguage,new Downloader());
h.post(new SuggestionResultRunnable(suggestions)); h.post(new SuggestionResultRunnable(suggestions));
} catch (ExtractionException e) { } catch (ExtractionException e) {
postNewErrorToast(h, R.string.parsing_error); ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list),
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.parsing_error));
e.printStackTrace(); e.printStackTrace();
} catch (IOException e) { } catch (IOException e) {
postNewErrorToast(h, R.string.network_error); postNewErrorToast(h, R.string.network_error);
e.printStackTrace(); e.printStackTrace();
} catch (Exception e) {
ErrorActivity.reportError(h, VideoItemListActivity.this, e, null, findViewById(R.id.videoitem_list),
ErrorActivity.ErrorInfo.make(ErrorActivity.SEARCHED,
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
} }
} }
} }

Wyświetl plik

@ -151,8 +151,6 @@ public class VideoItemListFragment extends ListFragment {
/* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error)); /* todo: this shoudl not be assigned static */ "Youtube", query, R.string.general_error));
e.printStackTrace(); e.printStackTrace();
} finally {
} }
} }
} }

Wyświetl plik

@ -25,9 +25,6 @@ public class ParsingException extends ExtractionException {
public ParsingException(String message) { public ParsingException(String message) {
super(message); super(message);
} }
public ParsingException(Throwable cause) {
super(cause);
}
public ParsingException(String message, Throwable cause) { public ParsingException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }

Wyświetl plik

@ -44,9 +44,6 @@ public interface StreamExtractor {
public ContentNotAvailableException(String message) { public ContentNotAvailableException(String message) {
super(message); super(message);
} }
public ContentNotAvailableException(Throwable cause) {
super(cause);
}
public ContentNotAvailableException(String message, Throwable cause) { public ContentNotAvailableException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }

Wyświetl plik

@ -137,8 +137,6 @@ public class YoutubeSearchEngine implements SearchEngine {
String response = dl.download(url); String response = dl.download(url);
try {
//TODO: Parse xml data using Jsoup not done //TODO: Parse xml data using Jsoup not done
DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder dBuilder; DocumentBuilder dBuilder;
@ -150,10 +148,10 @@ public class YoutubeSearchEngine implements SearchEngine {
new ByteArrayInputStream(response.getBytes("utf-8")))); new ByteArrayInputStream(response.getBytes("utf-8"))));
doc.getDocumentElement().normalize(); doc.getDocumentElement().normalize();
} catch (ParserConfigurationException | SAXException | IOException e) { } catch (ParserConfigurationException | SAXException | IOException e) {
e.printStackTrace(); throw new ParsingException("Could not parse document.");
} }
if (doc != null) { try {
NodeList nList = doc.getElementsByTagName("CompleteSuggestion"); NodeList nList = doc.getElementsByTagName("CompleteSuggestion");
for (int temp = 0; temp < nList.getLength(); temp++) { for (int temp = 0; temp < nList.getLength(); temp++) {
@ -164,12 +162,9 @@ public class YoutubeSearchEngine implements SearchEngine {
suggestions.add(eElement.getAttribute("data")); suggestions.add(eElement.getAttribute("data"));
} }
} }
} else {
Log.e(TAG, "GREAT FUCKING ERROR");
}
return suggestions; return suggestions;
} catch(Exception e) { } catch(Exception e) {
throw new ParsingException(e); throw new ParsingException("Could not get suggestions form document.", e);
} }
} }

Wyświetl plik

@ -52,9 +52,6 @@ public class YoutubeStreamExtractor implements StreamExtractor {
// exceptions // exceptions
public class DecryptException extends ParsingException { public class DecryptException extends ParsingException {
DecryptException(Throwable cause) {
super(cause);
}
DecryptException(String message, Throwable cause) { DecryptException(String message, Throwable cause) {
super(message, cause); super(message, cause);
} }
@ -718,7 +715,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
info.thumbnail_url = "https:" + info.thumbnail_url; info.thumbnail_url = "https:" + info.thumbnail_url;
} }
} catch (Exception e) { } catch (Exception e) {
throw new ParsingException(e); throw new ParsingException("Could not get video preview info", e);
} }
return info; return info;
} }
@ -772,7 +769,7 @@ public class YoutubeStreamExtractor implements StreamExtractor {
Function decryptionFunc = (Function) scope.get("decrypt", scope); Function decryptionFunc = (Function) scope.get("decrypt", scope);
result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig}); result = decryptionFunc.call(context, scope, scope, new Object[]{encryptedSig});
} catch (Exception e) { } catch (Exception e) {
throw new DecryptException(e); throw new DecryptException("could not get decrypt signature", e);
} finally { } finally {
Context.exit(); Context.exit();
} }