Bind methods instead of using eval

Reviewed By: astreet

Differential Revision: D3417452

fbshipit-source-id: 437daa2dfcd01efb749465a94c1a72ce8a2cb315
This commit is contained in:
Alexander Blom
2016-06-21 10:08:31 -07:00
committed by Facebook Github Bot 0
parent cd542f0656
commit d63d4f0e9c
9 changed files with 101 additions and 49 deletions

View File

@@ -25,7 +25,22 @@ import org.json.JSONObject;
* Tracks errors connecting to or received from the debug derver.
* The debug server returns errors as json objects. This exception represents that error.
*/
public class DebugServerException extends IOException {
public class DebugServerException extends RuntimeException {
private static final String GENERIC_ERROR_MESSAGE =
"\n\nTry the following to fix the issue:\n" +
"\u2022 Ensure that the packager server is running\n" +
"\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n" +
"\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n" +
"\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n";
public static DebugServerException makeGeneric(String reason, Throwable t) {
return makeGeneric(reason, "", t);
}
public static DebugServerException makeGeneric(String reason, String extra, Throwable t) {
return new DebugServerException(reason + GENERIC_ERROR_MESSAGE + extra, t);
}
private DebugServerException(String description, String fileName, int lineNumber, int column) {
super(description + "\n at " + fileName + ":" + lineNumber + ":" + column);
}
@@ -34,6 +49,10 @@ public class DebugServerException extends IOException {
super(description);
}
public DebugServerException(String detailMessage, Throwable throwable) {
super(detailMessage, throwable);
}
/**
* Parse a DebugServerException from the server json string.
* @param str json string returned by the debug server

View File

@@ -47,7 +47,6 @@ import okio.Sink;
* - Genymotion emulator with default settings: 10.0.3.2
*/
public class DevServerHelper {
public static final String RELOAD_APP_EXTRA_JS_PROXY = "jsproxy";
private static final String RELOAD_APP_ACTION_SUFFIX = ".RELOAD_APP_ACTION";
@@ -185,15 +184,10 @@ public class DevServerHelper {
}
mDownloadBundleFromURLCall = null;
StringBuilder sb = new StringBuilder();
sb.append("Could not connect to development server.\n\n")
.append("Try the following to fix the issue:\n")
.append("\u2022 Ensure that the packager server is running\n")
.append("\u2022 Ensure that your device/emulator is connected to your machine and has USB debugging enabled - run 'adb devices' to see a list of connected devices\n")
.append("\u2022 If you're on a physical device connected to the same machine, run 'adb reverse tcp:8081 tcp:8081' to forward requests from your device\n")
.append("\u2022 If your device is on the same Wi-Fi network, set 'Debug server host & port for device' in 'Dev settings' to your machine's IP address and the port of the local dev server - e.g. 10.0.1.1:8081\n\n")
.append("URL: ").append(call.request().url().toString());
callback.onFailure(new DebugServerException(sb.toString()));
callback.onFailure(DebugServerException.makeGeneric(
"Could not connect to development server.",
"URL: " + call.request().url().toString(),
e));
}
@Override