Skip to content

Commit 84acd5c

Browse files
committed
fix: remove redundat try catch block
1 parent 506f9b7 commit 84acd5c

File tree

1 file changed

+21
-28
lines changed

1 file changed

+21
-28
lines changed

packages/realtime_client/lib/src/realtime_channel.dart

Lines changed: 21 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -550,37 +550,30 @@ class RealtimeChannel {
550550
]
551551
};
552552

553-
try {
554-
final res = await (socket.httpClient?.post ?? post)(
555-
Uri.parse(broadcastEndpointURL),
556-
headers: headers,
557-
body: json.encode(body),
558-
).timeout(
559-
timeout ?? _timeout,
560-
onTimeout: () => throw TimeoutException('Request timeout'),
561-
);
562-
563-
if (res.statusCode == 202) {
564-
return;
565-
}
553+
final res = await (socket.httpClient?.post ?? post)(
554+
Uri.parse(broadcastEndpointURL),
555+
headers: headers,
556+
body: json.encode(body),
557+
).timeout(
558+
timeout ?? _timeout,
559+
onTimeout: () => throw TimeoutException('Request timeout'),
560+
);
566561

567-
String errorMessage = res.reasonPhrase ?? 'Unknown error';
568-
try {
569-
final errorBody = json.decode(res.body) as Map<String, dynamic>;
570-
errorMessage = (errorBody['error'] ??
571-
errorBody['message'] ??
572-
errorMessage) as String;
573-
} catch (_) {
574-
// If JSON parsing fails, use the default error message
575-
}
562+
if (res.statusCode == 202) {
563+
return;
564+
}
576565

577-
throw Exception(errorMessage);
578-
} catch (e) {
579-
if (e is TimeoutException) {
580-
rethrow;
581-
}
582-
throw Exception(e.toString());
566+
String errorMessage = res.reasonPhrase ?? 'Unknown error';
567+
try {
568+
final errorBody = json.decode(res.body) as Map<String, dynamic>;
569+
errorMessage = (errorBody['error'] ??
570+
errorBody['message'] ??
571+
errorMessage) as String;
572+
} catch (_) {
573+
// If JSON parsing fails, use the default error message
583574
}
575+
576+
throw Exception(errorMessage);
584577
}
585578

586579
/// Sends a realtime broadcast message.

0 commit comments

Comments
 (0)