jenkins-bot has submitted this change and it was merged.

Change subject: Check for "internal error" when fetching styles from server.
......................................................................


Check for "internal error" when fetching styles from server.

Change-Id: Ic2179e81fef573f896357726adc56efbe5196de3
---
M wikipedia/src/main/java/org/wikipedia/bridge/StyleFetcherTask.java
1 file changed, 19 insertions(+), 1 deletion(-)

Approvals:
  BearND: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/wikipedia/src/main/java/org/wikipedia/bridge/StyleFetcherTask.java 
b/wikipedia/src/main/java/org/wikipedia/bridge/StyleFetcherTask.java
index 36af63a..a316e77 100644
--- a/wikipedia/src/main/java/org/wikipedia/bridge/StyleFetcherTask.java
+++ b/wikipedia/src/main/java/org/wikipedia/bridge/StyleFetcherTask.java
@@ -11,6 +11,7 @@
 import org.wikipedia.recurring.RecurringTask;
 import org.wikipedia.settings.PrefKeys;
 
+import java.io.BufferedInputStream;
 import java.io.OutputStream;
 import java.io.UnsupportedEncodingException;
 import java.net.URLEncoder;
@@ -62,8 +63,25 @@
                 // Only overwrite files if we get a 200
                 // This prevents empty style files from being used when 
betalabs goes down
                 if (request.ok()) {
+
+                    // NB: this is a quick hack. The real solution is for the 
server to NOT return
+                    // a status of 200, when in fact there's an internal error!
+                    // We will "preview" the first few bytes of the stream, 
and check if they
+                    // actually contain the words "internal error"!
+                    BufferedInputStream stream = new 
BufferedInputStream(request.stream());
+                    final int numPreviewBytes = 32;
+                    byte[] previewBytes = new byte[numPreviewBytes];
+                    stream.mark(numPreviewBytes + 1);
+                    stream.read(previewBytes);
+                    stream.reset();
+                    String preview = new String(previewBytes);
+                    if (preview.contains("nternal error")) { //ignore case of 
"internal"
+                        return;
+                    }
+                    // end of hack
+
                     OutputStream fo = 
getContext().openFileOutput(styleSpec[0], Context.MODE_PRIVATE);
-                    Utils.copyStreams(request.stream(), fo);
+                    Utils.copyStreams(stream, fo);
                     fo.close();
                     Log.d("Wikipedia", String.format("Downloaded %s into %s", 
url, getContext().getFileStreamPath(styleSpec[0]).getAbsolutePath()));
                 } else {

-- 
To view, visit https://gerrit.wikimedia.org/r/165939
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: Ic2179e81fef573f896357726adc56efbe5196de3
Gerrit-PatchSet: 5
Gerrit-Project: apps/android/wikipedia
Gerrit-Branch: master
Gerrit-Owner: Dbrant <[email protected]>
Gerrit-Reviewer: BearND <[email protected]>
Gerrit-Reviewer: Brion VIBBER <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to