add error handling to getRecentMessage and getAssets in chat store
getRecentMessage had no try/catch, so a failure from the third-party API would silently prevent connectToChat from ever being called. getAssets was fire-and-forget without a catchError, risking uncaught Future errors. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
7a9af238b6
commit
929d525c13
1 changed files with 12 additions and 6 deletions
|
|
@ -875,7 +875,9 @@ abstract class ChatStoreBase with Store {
|
|||
@action
|
||||
Future<void> connectToChat({bool isReconnect = false}) async {
|
||||
// Fetch assets first so they're available for all messages
|
||||
getAssets();
|
||||
getAssets().catchError(
|
||||
(e) => debugPrint('Failed to fetch chat assets: $e'),
|
||||
);
|
||||
|
||||
// Cancel existing listener to prevent duplicate message processing
|
||||
_channelListener?.cancel();
|
||||
|
|
@ -1301,12 +1303,16 @@ abstract class ChatStoreBase with Store {
|
|||
|
||||
@action
|
||||
Future<void> getRecentMessage() async {
|
||||
final recentMessages = await twitchApi.getRecentMessages(
|
||||
userLogin: channelName,
|
||||
);
|
||||
try {
|
||||
final recentMessages = await twitchApi.getRecentMessages(
|
||||
userLogin: channelName,
|
||||
);
|
||||
|
||||
for (final message in recentMessages) {
|
||||
_handleIRCData(message);
|
||||
for (final message in recentMessages) {
|
||||
_handleIRCData(message);
|
||||
}
|
||||
} catch (e) {
|
||||
debugPrint('Failed to fetch recent messages: $e');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue