Skip to content

Commit bad5afb

Browse files
committed
Fixed Server Backend Error handling
1 parent 284cfff commit bad5afb

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

.idea/appInsightsSettings.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/deploymentTargetSelector.xml

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ android {
2525
applicationId "com.noti.main"
2626
minSdkVersion 23
2727
targetSdkVersion 34
28-
versionCode 1012103
29-
versionName "1.21.3"
28+
versionCode 1012104
29+
versionName "1.21.4"
3030

3131
multiDexEnabled true
3232
ndk.abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'
@@ -97,7 +97,7 @@ dependencies {
9797
implementation 'com.google.android.gms:play-services-auth:21.2.0'
9898
implementation 'com.google.android.gms:play-services-location:21.3.0'
9999
implementation 'com.google.android.gms:play-services-maps:19.0.0'
100-
implementation 'com.google.auth:google-auth-library-oauth2-http:1.23.0'
100+
implementation 'com.google.auth:google-auth-library-oauth2-http:1.24.0'
101101

102102
implementation platform('com.google.firebase:firebase-bom:33.1.2')
103103
implementation 'com.google.firebase:firebase-auth'
@@ -108,14 +108,14 @@ dependencies {
108108
implementation 'com.google.firebase:firebase-config'
109109
implementation 'com.google.firebase:firebase-storage'
110110

111-
implementation 'me.pushy:sdk:1.0.111'
111+
implementation 'me.pushy:sdk:1.0.112'
112112
implementation "com.github.mvojtkovszky:BillingHelper:3.0.0"
113113
implementation 'com.android.volley:volley:1.2.1'
114114
implementation 'com.github.bumptech.glide:glide:4.16.0'
115115
implementation 'com.github.isradeleon:Notify-Android:1.0.4'
116116
implementation 'com.github.KieronQuinn:MonetCompat:0.4.1'
117117
implementation 'com.joaomgcd:taskerpluginlibrary:0.4.10'
118-
implementation 'com.microsoft.design:fluent-system-icons:1.1.247@aar'
118+
implementation 'com.microsoft.design:fluent-system-icons:1.1.249@aar'
119119
implementation 'org.jetbrains.kotlin:kotlin-stdlib-jdk8:2.0.0'
120120
}
121121

app/src/main/java/com/noti/main/service/backend/PacketRequester.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import com.android.volley.Request;
77
import com.android.volley.Response;
8+
import com.android.volley.VolleyError;
89
import com.android.volley.toolbox.JsonObjectRequest;
910
import androidx.annotation.Nullable;
1011

@@ -20,7 +21,6 @@
2021

2122
import java.util.HashMap;
2223
import java.util.Map;
23-
import java.util.Objects;
2424

2525
public class PacketRequester {
2626
public static void addToRequestQueue(Context context, String serviceType, JSONObject packetBody,
@@ -40,13 +40,20 @@ public static void addToRequestQueue(Context context, String serviceType, JSONOb
4040
FirebaseUser mUser = FirebaseAuth.getInstance().getCurrentUser();
4141
if(mUser != null) {
4242
mUser.getIdToken(true)
43-
.addOnFailureListener(task -> Objects.requireNonNull(task.getCause()).printStackTrace())
43+
.addOnFailureListener(task -> {
44+
if(errorListener != null) {
45+
errorListener.onErrorResponse(new VolleyError("Firebase Authentication Failed"));
46+
}
47+
})
4448
.addOnCompleteListener(task -> {
4549
if (task.isSuccessful()) {
4650
String idToken = task.getResult().getToken();
4751
postPacket(context, idToken, URI, packetBody, listener, errorListener);
4852
} else {
49-
Objects.requireNonNull(task.getException()).printStackTrace();
53+
Exception exception = task.getException();
54+
if(exception != null && errorListener != null) {
55+
errorListener.onErrorResponse(new VolleyError(exception.getMessage()));
56+
}
5057
}
5158
});
5259
}

app/src/main/java/com/noti/main/ui/options/OtherPreference.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.noti.main.utils.network.AESCrypto;
3636
import com.noti.main.utils.ui.ToastHelper;
3737

38-
import org.json.JSONException;
3938
import org.json.JSONObject;
4039

4140
import java.io.IOException;
@@ -414,26 +413,37 @@ public boolean onPreferenceTreeClick(Preference preference) {
414413
throw new RuntimeException(e);
415414
}
416415
}, error -> {
417-
String cause = """
416+
MaterialAlertDialogBuilder errorDialog = new MaterialAlertDialogBuilder(new ContextThemeWrapper(mContext, R.style.Theme_App_Palette_Dialog));
417+
String cause;
418+
419+
if(error.networkResponse == null) {
420+
cause = """
418421
Time taken: %d (ms)
419-
Error code: %d
422+
Exception: %s
420423
""";
421-
MaterialAlertDialogBuilder errorDialog = new MaterialAlertDialogBuilder(new ContextThemeWrapper(mContext, R.style.Theme_App_Palette_Dialog));
424+
errorDialog.setMessage(String.format(Locale.getDefault(), cause, (System.currentTimeMillis() - currentTime), error.getMessage()));
425+
} else {
426+
cause = """
427+
Time taken: %d (ms)
428+
Error code: %s
429+
""";
430+
errorDialog.setMessage(String.format(Locale.getDefault(), cause, (System.currentTimeMillis() - currentTime), error.networkResponse.statusCode));
431+
}
432+
422433
errorDialog.setTitle("Test Failed");
423434
errorDialog.setIcon(R.drawable.ic_info_outline_black_24dp);
424-
errorDialog.setMessage(String.format(Locale.getDefault(), cause, (System.currentTimeMillis() - currentTime), error.networkResponse.statusCode));
425435
errorDialog.setPositiveButton("Close", (d, w) -> { });
426436
errorDialog.show();
427437
});
428-
} catch (JSONException e) {
438+
} catch (Exception e) {
429439
String cause = """
430440
Time taken: %d (ms)
431441
Exception: %s
432442
""";
433443
MaterialAlertDialogBuilder errorDialog = new MaterialAlertDialogBuilder(new ContextThemeWrapper(mContext, R.style.Theme_App_Palette_Dialog));
434444
errorDialog.setTitle("Test Failed");
435445
errorDialog.setIcon(R.drawable.ic_info_outline_black_24dp);
436-
errorDialog.setMessage(String.format(Locale.getDefault(), cause, (System.currentTimeMillis() - currentTime), e.getCause()));
446+
errorDialog.setMessage(String.format(Locale.getDefault(), cause, (System.currentTimeMillis() - currentTime), e.getMessage()));
437447
errorDialog.setPositiveButton("Close", (d, w) -> { });
438448
errorDialog.show();
439449
}

0 commit comments

Comments
 (0)