From 38854b3ca7d36cbb8d26e6113c6e2c3d742aa45f Mon Sep 17 00:00:00 2001 From: Andrew Stephan Date: Tue, 8 Apr 2014 13:08:58 -0400 Subject: [PATCH] send back status 0 when the host cannot be resolved to match iOS. Also removed some logs --- src/android/com/synconset/CordovaHTTP/CordovaHttp.java | 8 ++++++-- .../com/synconset/CordovaHTTP/CordovaHttpDownload.java | 7 +++++-- .../com/synconset/CordovaHTTP/CordovaHttpGet.java | 7 +++++-- .../com/synconset/CordovaHTTP/CordovaHttpPlugin.java | 1 - .../com/synconset/CordovaHTTP/CordovaHttpPost.java | 9 ++++++--- .../com/synconset/CordovaHTTP/CordovaHttpUpload.java | 6 +++++- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttp.java b/src/android/com/synconset/CordovaHTTP/CordovaHttp.java index 99dd62b..e90ad6f 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttp.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttp.java @@ -89,14 +89,18 @@ public abstract class CordovaHttp { return request; } - protected void respondWithError(String msg) { + protected void respondWithError(int status, String msg) { try { JSONObject response = new JSONObject(); - response.put("status", 500); + response.put("status", status); response.put("error", msg); this.callbackContext.error(response); } catch (JSONException e) { this.callbackContext.error(msg); } } + + protected void respondWithError(String msg) { + this.respondWithError(500, msg); + } } diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpDownload.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpDownload.java index 51262b2..b70d0a0 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttpDownload.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpDownload.java @@ -54,8 +54,11 @@ public class CordovaHttpDownload extends CordovaHttp implements Runnable { } catch (JSONException e) { this.respondWithError("There was an error generating the response"); } catch (HttpRequestException e) { - Log.d(TAG, e.getMessage()); - 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"); + } } } } diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java index b23c0c6..343b1be 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java @@ -48,8 +48,11 @@ public class CordovaHttpGet extends CordovaHttp implements Runnable { } catch (JSONException e) { this.respondWithError("There was an error generating the response"); } catch (HttpRequestException e) { - Log.d(TAG, e.getMessage()); - 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"); + } } } } \ No newline at end of file diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java index 6571448..6799168 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java @@ -78,7 +78,6 @@ public class CordovaHttpPlugin extends CordovaPlugin { callbackContext.success(); } catch(Exception e) { e.printStackTrace(); - Log.d(TAG, e.getMessage()); callbackContext.error("There was an error setting up ssl pinning"); } } else if (action.equals("acceptAllCerts")) { diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java index c257927..a944954 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java @@ -3,6 +3,7 @@ */ package com.synconset; +import java.net.UnknownHostException; import java.util.Map; import org.apache.cordova.CallbackContext; @@ -39,11 +40,13 @@ public class CordovaHttpPost extends CordovaHttp implements Runnable { this.getCallbackContext().error(response); } } catch (JSONException e) { - Log.d(TAG, e.getMessage()); this.respondWithError("There was an error generating the response"); } catch (HttpRequestException e) { - Log.d(TAG, e.getMessage()); - 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"); + } } } } diff --git a/src/android/com/synconset/CordovaHTTP/CordovaHttpUpload.java b/src/android/com/synconset/CordovaHTTP/CordovaHttpUpload.java index 35788bd..68bb1bc 100644 --- a/src/android/com/synconset/CordovaHTTP/CordovaHttpUpload.java +++ b/src/android/com/synconset/CordovaHTTP/CordovaHttpUpload.java @@ -80,7 +80,11 @@ public class CordovaHttpUpload extends CordovaHttp implements Runnable { } catch (JSONException e) { this.respondWithError("There was an error generating the response"); } 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"); + } } } }