Rapsssito / react-native-tcp-socket

React Native TCP socket API for Android, iOS & macOS with SSL/TLS support.
MIT License
303 stars 81 forks source link

Wrong error message on iOS ("error in connect() function") #170

Closed jesperjohansson closed 1 year ago

jesperjohansson commented 1 year ago

On iOS you always receive the error message "error in connect() function". By switching to localizedDescription we could get more specific error messages such as "Connection refused".

patch-package:

diff --git a/node_modules/react-native-tcp-socket/ios/TcpSockets.m b/node_modules/react-native-tcp-socket/ios/TcpSockets.m
index 23c961f..3a9783a 100644
--- a/node_modules/react-native-tcp-socket/ios/TcpSockets.m
+++ b/node_modules/react-native-tcp-socket/ios/TcpSockets.m
@@ -283,7 +283,7 @@ - (void)onClose:(NSNumber *)clientID withError:(NSError *)err {
 }

 - (void)onError:(TcpSocketClient *)client withError:(NSError *)err {
-    NSString *msg = err.localizedFailureReason ?: err.localizedDescription;
+    NSString *msg = err.localizedDescription ?: err.localizedFailureReason;
     [self sendEventWithName:@"error" body:@{@"id" : client.id, @"error" : msg}];
 }
github-actions[bot] commented 1 year ago

:tada: This issue has been resolved in version 6.0.5 :tada:

The release is available on:

Your semantic-release bot :package::rocket: