@capgo/capacitor-updater 4.14.1 → 4.14.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,10 +11,12 @@ import android.os.Bundle;
11
11
  import android.util.Base64;
12
12
  import android.util.Log;
13
13
  import com.android.volley.BuildConfig;
14
+ import com.android.volley.NetworkResponse;
14
15
  import com.android.volley.Request;
15
16
  import com.android.volley.RequestQueue;
16
17
  import com.android.volley.Response;
17
18
  import com.android.volley.VolleyError;
19
+ import com.android.volley.toolbox.HttpHeaderParser;
18
20
  import com.android.volley.toolbox.JsonObjectRequest;
19
21
  import com.getcapacitor.JSObject;
20
22
  import com.getcapacitor.plugin.WebView;
@@ -27,6 +29,7 @@ import java.io.FileOutputStream;
27
29
  import java.io.FilenameFilter;
28
30
  import java.io.IOException;
29
31
  import java.io.InputStream;
32
+ import java.io.UnsupportedEncodingException;
30
33
  import java.net.URL;
31
34
  import java.net.URLConnection;
32
35
  import java.security.GeneralSecurityException;
@@ -60,7 +63,7 @@ public class CapacitorUpdater {
60
63
  private static final String bundleDirectory = "versions";
61
64
 
62
65
  public static final String TAG = "Capacitor-updater";
63
- public static final String pluginVersion = "4.14.1";
66
+ public static final String pluginVersion = "4.14.2";
64
67
 
65
68
  public SharedPreferences.Editor editor;
66
69
  public SharedPreferences prefs;
@@ -672,6 +675,29 @@ public class CapacitorUpdater {
672
675
  return json;
673
676
  }
674
677
 
678
+ private JSObject createError(String message, VolleyError error) {
679
+ NetworkResponse response = error.networkResponse;
680
+ final JSObject retError = new JSObject();
681
+ retError.put("error", "response_error");
682
+ if (response != null) {
683
+ try {
684
+ String json = new String(
685
+ response.data,
686
+ HttpHeaderParser.parseCharset(response.headers)
687
+ );
688
+ Log.e(TAG, message + ": " + json);
689
+ retError.put("message", message + ": " + json);
690
+ } catch (UnsupportedEncodingException e) {
691
+ Log.e(TAG, message + ": " + e.toString());
692
+ retError.put("message", message + ": " + e.toString());
693
+ }
694
+ } else {
695
+ Log.e(TAG, message + ": " + error.toString());
696
+ retError.put("message", message + ": " + error.toString());
697
+ }
698
+ return retError;
699
+ }
700
+
675
701
  public void getLatest(final String updateUrl, final Callback callback) {
676
702
  JSONObject json = null;
677
703
  try {
@@ -717,11 +743,9 @@ public class CapacitorUpdater {
717
743
  new Response.ErrorListener() {
718
744
  @Override
719
745
  public void onErrorResponse(VolleyError error) {
720
- Log.e(TAG, "Error getting Latest" + error.toString());
721
- final JSObject retError = new JSObject();
722
- retError.put("message", "Cannot set info: " + error.toString());
723
- retError.put("error", "response_error");
724
- callback.callback(retError);
746
+ callback.callback(
747
+ CapacitorUpdater.this.createError("Error get latest", error)
748
+ );
725
749
  }
726
750
  }
727
751
  );
@@ -784,11 +808,9 @@ public class CapacitorUpdater {
784
808
  new Response.ErrorListener() {
785
809
  @Override
786
810
  public void onErrorResponse(VolleyError error) {
787
- Log.e(TAG, "Error set channel: " + error.toString());
788
- final JSObject retError = new JSObject();
789
- retError.put("message", "Cannot set channel: " + error.toString());
790
- retError.put("error", "response_error");
791
- callback.callback(retError);
811
+ callback.callback(
812
+ CapacitorUpdater.this.createError("Error set channel", error)
813
+ );
792
814
  }
793
815
  }
794
816
  );
@@ -846,11 +868,9 @@ public class CapacitorUpdater {
846
868
  new Response.ErrorListener() {
847
869
  @Override
848
870
  public void onErrorResponse(VolleyError error) {
849
- Log.e(TAG, "Error get channel: " + error.toString());
850
- final JSObject retError = new JSObject();
851
- retError.put("message", "Error get channel: " + error.toString());
852
- retError.put("error", "response_error");
853
- callback.callback(retError);
871
+ callback.callback(
872
+ CapacitorUpdater.this.createError("Error get channel", error)
873
+ );
854
874
  }
855
875
  }
856
876
  );
@@ -888,7 +908,7 @@ public class CapacitorUpdater {
888
908
  new Response.ErrorListener() {
889
909
  @Override
890
910
  public void onErrorResponse(VolleyError error) {
891
- Log.e(TAG, "Error sending stats: " + error.toString());
911
+ CapacitorUpdater.this.createError("Error send stats", error);
892
912
  }
893
913
  }
894
914
  );
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@capgo/capacitor-updater",
3
- "version": "4.14.1",
3
+ "version": "4.14.2",
4
4
  "license": "LGPL-3.0-only",
5
5
  "description": "OTA update for capacitor apps",
6
6
  "main": "dist/plugin.cjs.js",