diff --git a/iOS/FlipperKit/FlipperWebSocket.mm b/iOS/FlipperKit/FlipperWebSocket.mm index 29a9113bd..3389d7791 100644 --- a/iOS/FlipperKit/FlipperWebSocket.mm +++ b/iOS/FlipperKit/FlipperWebSocket.mm @@ -9,12 +9,12 @@ #import "FlipperWebSocket.h" #import +#import #import #import #import #import #import -#import #import #import #import @@ -94,9 +94,7 @@ bool FlipperWebSocket::connect(FlipperConnectionManager* manager) { } else if (event == SocketEvent::SSL_ERROR) { try { promise.set_exception( - std::make_exception_ptr(folly::AsyncSocketException( - folly::AsyncSocketException::SSL_ERROR, - "SSL handshake failed"))); + std::make_exception_ptr(SSLException("SSL handshake failed"))); } catch (...) { // set_exception() may throw an exception // In that case, just set the value to false. diff --git a/xplat/Flipper/FlipperConnectionManagerImpl.cpp b/xplat/Flipper/FlipperConnectionManagerImpl.cpp index 66e59640d..ee2dab331 100644 --- a/xplat/Flipper/FlipperConnectionManagerImpl.cpp +++ b/xplat/Flipper/FlipperConnectionManagerImpl.cpp @@ -8,13 +8,13 @@ #include "FlipperConnectionManagerImpl.h" #include #include -#include #include #include #include #include #include "ConnectionContextStore.h" #include "FireAndForgetBasedFlipperResponder.h" +#include "FlipperExceptions.h" #include "FlipperSocketProvider.h" #include "FlipperStep.h" #include "Log.h" @@ -178,16 +178,11 @@ void FlipperConnectionManagerImpl::startSync() { } } step->complete(); - } catch (const folly::AsyncSocketException& e) { - if (e.getType() == folly::AsyncSocketException::SSL_ERROR) { - auto message = std::string(e.what()) + - "\nMake sure the date and time of your device is up to date."; - log(message); - step->fail(message); - } else { - log(e.what()); - step->fail(e.what()); - } + } catch (const SSLException& e) { + auto message = std::string(e.what()) + + "\nMake sure the date and time of your device is up to date."; + log(message); + step->fail(message); failedConnectionAttempts_++; reconnect(); } catch (const std::exception& e) { diff --git a/xplat/Flipper/FlipperExceptions.h b/xplat/Flipper/FlipperExceptions.h new file mode 100644 index 000000000..385db6296 --- /dev/null +++ b/xplat/Flipper/FlipperExceptions.h @@ -0,0 +1,30 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +#pragma once + +namespace facebook { +namespace flipper { + +class SSLException : public std::exception { + public: + explicit SSLException(const char* message) : msg_(message) {} + + explicit SSLException(const std::string& message) : msg_(message) {} + + virtual ~SSLException() noexcept {} + + virtual const char* what() const noexcept { + return msg_.c_str(); + } + + protected: + std::string msg_; +}; + +} // namespace flipper +} // namespace facebook diff --git a/xplat/FlipperWebSocket/WebSocketClient.cpp b/xplat/FlipperWebSocket/WebSocketClient.cpp index 5e85007ab..b828a61b3 100644 --- a/xplat/FlipperWebSocket/WebSocketClient.cpp +++ b/xplat/FlipperWebSocket/WebSocketClient.cpp @@ -14,7 +14,6 @@ #include #include #include -#include #include #include #include diff --git a/xplat/FlipperWebSocket/WebSocketTLSClient.cpp b/xplat/FlipperWebSocket/WebSocketTLSClient.cpp index be3357fcb..f4b029797 100644 --- a/xplat/FlipperWebSocket/WebSocketTLSClient.cpp +++ b/xplat/FlipperWebSocket/WebSocketTLSClient.cpp @@ -9,12 +9,12 @@ #include "WebSocketTLSClient.h" #include +#include #include #include #include #include #include -#include #include #include #include @@ -246,9 +246,7 @@ void WebSocketTLSClient::onFail( if (sslError) { try { connected_.set_exception( - std::make_exception_ptr(folly::AsyncSocketException( - folly::AsyncSocketException::SSL_ERROR, - "SSL handshake failed"))); + std::make_exception_ptr(SSLException("SSL handshake failed"))); } catch (...) { // set_exception() may throw an exception // In that case, just set the value to false.