mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2024-10-07 01:32:12 +08:00
send back status 0 when the host cannot be resolved to match iOS. Also removed some logs
This commit is contained in:
parent
d55f1bdc20
commit
38854b3ca7
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -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")) {
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user