Skip to content

Commit 4dfbe86

Browse files
committed
Refactor Ejson class to use UnsupportedEncodingException for URI encoding errors
- Updated avatar URI generation to specify "UTF-8" encoding instead of StandardCharsets.UTF_8. - Changed exception handling to catch UnsupportedEncodingException specifically for better clarity in error logging.
1 parent 5ee2de6 commit 4dfbe86

File tree

1 file changed

+5
-5
lines changed
  • android/app/src/main/java/chat/rocket/reactnative/notification

1 file changed

+5
-5
lines changed

android/app/src/main/java/chat/rocket/reactnative/notification/Ejson.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
import java.math.BigInteger;
99
import java.net.URLEncoder;
10-
import java.nio.charset.StandardCharsets;
10+
import java.io.UnsupportedEncodingException;
1111

1212
import chat.rocket.reactnative.BuildConfig;
1313
import chat.rocket.reactnative.storage.MMKVKeyManager;
@@ -85,11 +85,11 @@ public String getAvatarUri() {
8585
return null;
8686
}
8787
try {
88-
avatarPath = "/avatar/" + URLEncoder.encode(sender.username, StandardCharsets.UTF_8);
88+
avatarPath = "/avatar/" + URLEncoder.encode(sender.username, "UTF-8");
8989
if (BuildConfig.DEBUG) {
9090
Log.d(TAG, "Generated avatar URI for user: " + sender.username);
9191
}
92-
} catch (Exception e) {
92+
} catch (UnsupportedEncodingException e) {
9393
Log.e(TAG, "Failed to encode username", e);
9494
return null;
9595
}
@@ -100,11 +100,11 @@ public String getAvatarUri() {
100100
return null;
101101
}
102102
try {
103-
avatarPath = "/avatar/room/" + URLEncoder.encode(rid, StandardCharsets.UTF_8);
103+
avatarPath = "/avatar/room/" + URLEncoder.encode(rid, "UTF-8");
104104
if (BuildConfig.DEBUG) {
105105
Log.d(TAG, "Generated avatar URI for room: " + rid);
106106
}
107-
} catch (Exception e) {
107+
} catch (UnsupportedEncodingException e) {
108108
Log.e(TAG, "Failed to encode rid", e);
109109
return null;
110110
}

0 commit comments

Comments
 (0)