send back status 0 when the host cannot be resolved to match iOS. Also removed some logs

This commit is contained in:
Andrew Stephan 2014-04-08 13:08:58 -04:00
parent d55f1bdc20
commit 38854b3ca7
6 changed files with 27 additions and 11 deletions

View File

@ -89,14 +89,18 @@ public abstract class CordovaHttp {
return request; return request;
} }
protected void respondWithError(String msg) { protected void respondWithError(int status, String msg) {
try { try {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
response.put("status", 500); response.put("status", status);
response.put("error", msg); response.put("error", msg);
this.callbackContext.error(response); this.callbackContext.error(response);
} catch (JSONException e) { } catch (JSONException e) {
this.callbackContext.error(msg); this.callbackContext.error(msg);
} }
} }
protected void respondWithError(String msg) {
this.respondWithError(500, msg);
}
} }

View File

@ -54,8 +54,11 @@ public class CordovaHttpDownload extends CordovaHttp implements Runnable {
} catch (JSONException e) { } catch (JSONException e) {
this.respondWithError("There was an error generating the response"); this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
Log.d(TAG, e.getMessage()); if (e.getCause() instanceof UnknownHostException) {
this.respondWithError("There was an error with the request"); this.respondWithError(0, "The host could not be resolved");
} else {
this.respondWithError("There was an error with the request");
}
} }
} }
} }

View File

@ -48,8 +48,11 @@ public class CordovaHttpGet extends CordovaHttp implements Runnable {
} catch (JSONException e) { } catch (JSONException e) {
this.respondWithError("There was an error generating the response"); this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
Log.d(TAG, e.getMessage()); if (e.getCause() instanceof UnknownHostException) {
this.respondWithError("There was an error with the request"); this.respondWithError(0, "The host could not be resolved");
} else {
this.respondWithError("There was an error with the request");
}
} }
} }
} }

View File

@ -78,7 +78,6 @@ public class CordovaHttpPlugin extends CordovaPlugin {
callbackContext.success(); callbackContext.success();
} catch(Exception e) { } catch(Exception e) {
e.printStackTrace(); e.printStackTrace();
Log.d(TAG, e.getMessage());
callbackContext.error("There was an error setting up ssl pinning"); callbackContext.error("There was an error setting up ssl pinning");
} }
} else if (action.equals("acceptAllCerts")) { } else if (action.equals("acceptAllCerts")) {

View File

@ -3,6 +3,7 @@
*/ */
package com.synconset; package com.synconset;
import java.net.UnknownHostException;
import java.util.Map; import java.util.Map;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
@ -39,11 +40,13 @@ public class CordovaHttpPost extends CordovaHttp implements Runnable {
this.getCallbackContext().error(response); this.getCallbackContext().error(response);
} }
} catch (JSONException e) { } catch (JSONException e) {
Log.d(TAG, e.getMessage());
this.respondWithError("There was an error generating the response"); this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
Log.d(TAG, e.getMessage()); if (e.getCause() instanceof UnknownHostException) {
this.respondWithError("There was an error with the request"); this.respondWithError(0, "The host could not be resolved");
} else {
this.respondWithError("There was an error with the request");
}
} }
} }
} }

View File

@ -80,7 +80,11 @@ public class CordovaHttpUpload extends CordovaHttp implements Runnable {
} catch (JSONException e) { } catch (JSONException e) {
this.respondWithError("There was an error generating the response"); this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
this.respondWithError("There was an error with the request"); if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved");
} else {
this.respondWithError("There was an error with the request");
}
} }
} }
} }