Skip to content

Commit

Permalink
Catch all exceptions in BTTV/FFZ apis
Browse files Browse the repository at this point in the history
  • Loading branch information
mini-bomba committed Nov 13, 2023
1 parent 9f0d8db commit 9e16302
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
7 changes: 3 additions & 4 deletions src/main/java/me/mini_bomba/streamchatmod/utils/BTTVApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.*;
Expand All @@ -20,7 +19,7 @@ public static List<BTTVEmote> getGlobalEmotes() {
try {
LocalEmote[] emotes = gson.fromJson(new InputStreamReader(new URL("https://api.betterttv.net/3/cached/emotes/global").openStream()), LocalEmote[].class);
return Arrays.stream(emotes).map(emote -> new BTTVEmote(emote.id, emote.code, getImageType(emote.imageType), emote.userId)).collect(Collectors.toList());
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch BTTV global emotes:");
e.printStackTrace();
return Collections.emptyList();
Expand All @@ -38,7 +37,7 @@ public static List<BTTVEmote> getChannelEmotes(String twitchId) {
return new BTTVEmote(emote.id, emote.code, getImageType(emote.imageType), emote.user.id);
})
).collect(Collectors.toList());
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch BTTV channel emotes:");
e.printStackTrace();
return Collections.emptyList();
Expand All @@ -63,7 +62,7 @@ private static BTTVUser getBTTVUser(String userId) {
Gson gson = new Gson();
try {
return gson.fromJson(new InputStreamReader(new URL("https://api.betterttv.net/3/users/" + userId).openStream()), BTTVUser.class);
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch BTTV user");
e.printStackTrace();
return null;
Expand Down
7 changes: 3 additions & 4 deletions src/main/java/me/mini_bomba/streamchatmod/utils/FFZApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.util.Collections;
Expand All @@ -20,7 +19,7 @@ public static List<FFZEmote> getGlobalEmotes() {
try {
FFZDefaultSets sets = gson.fromJson(new InputStreamReader(new URL("https://api.frankerfacez.com/v1/set/global").openStream()), FFZDefaultSets.class);
return sets.sets.get("3").emoticons;
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch FFZ global emotes:");
e.printStackTrace();
return Collections.emptyList();
Expand All @@ -34,7 +33,7 @@ public static List<FFZEmote> getChannelEmotes(String channelId) {
if (resp.room == null || !resp.sets.containsKey(String.valueOf(resp.room.set)))
return Collections.emptyList();
return resp.sets.get(String.valueOf(resp.room.set)).emoticons;
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch FFZ channel emotes for id " + channelId + ":");
e.printStackTrace();
return Collections.emptyList();
Expand All @@ -46,7 +45,7 @@ public static Map<String, List<FFZEmote>> getMultiChannelEmotes(List<String> cha
try {
FFZMultiRoomResponse resp = gson.fromJson(new InputStreamReader(new URL("https://api.frankerfacez.com/v1/multi_room/id/" + String.join(",", channelIds)).openStream()), FFZMultiRoomResponse.class);
return resp.rooms.stream().collect(Collectors.toMap(room -> String.valueOf(room.twitch_id), room -> resp.sets.containsKey(String.valueOf(room.set)) ? resp.sets.get(String.valueOf(room.set)).emoticons : Collections.emptyList()));
} catch (IOException e) {
} catch (Exception e) {
LOGGER.error("Failed to fetch FFZ channel emotes for ids " + String.join(",", channelIds) + ":");
e.printStackTrace();
return channelIds.stream().collect(Collectors.toMap(i -> i, i -> Collections.emptyList()));
Expand Down

0 comments on commit 9e16302

Please sign in to comment.