@@ -68,7 +68,6 @@ final class SubscriptionEndpoint {
6868 private final GraphQLResponse .Factory responseFactory ;
6969 private final TimeoutWatchdog timeoutWatchdog ;
7070 private final Set <String > pendingSubscriptionIds ;
71- private final String subscriptionUrl ;
7271 private final OkHttpClient okHttpClient ;
7372 private WebSocket webSocket ;
7473 private AmplifyWebSocketListener webSocketListener ;
@@ -84,7 +83,6 @@ final class SubscriptionEndpoint {
8483 this .authorizer = Objects .requireNonNull (authorizer );
8584 this .timeoutWatchdog = new TimeoutWatchdog ();
8685 this .pendingSubscriptionIds = Collections .synchronizedSet (new HashSet <>());
87- this .subscriptionUrl = buildConnectionRequestUrl ();
8886 this .okHttpClient = new OkHttpClient .Builder ()
8987 .addNetworkInterceptor (UserAgentInterceptor .using (UserAgent ::string ))
9088 .retryOnConnectionFailure (true )
@@ -107,10 +105,16 @@ synchronized <T> void requestSubscription(
107105 // force a new connection to be created.
108106 if (webSocketListener == null || webSocketListener .isDisconnectedState ()) {
109107 webSocketListener = new AmplifyWebSocketListener ();
110- webSocket = okHttpClient .newWebSocket (new Request .Builder ()
111- .url (subscriptionUrl )
112- .addHeader ("Sec-WebSocket-Protocol" , "graphql-ws" )
113- .build (), webSocketListener );
108+ try {
109+ webSocket = okHttpClient .newWebSocket (new Request .Builder ()
110+ .url (buildConnectionRequestUrl ())
111+ .addHeader ("Sec-WebSocket-Protocol" , "graphql-ws" )
112+ .build (), webSocketListener );
113+ } catch (ApiException apiException ) {
114+ onSubscriptionError .accept (apiException );
115+ return ;
116+ }
117+
114118 }
115119 final String subscriptionId = UUID .randomUUID ().toString ();
116120 pendingSubscriptionIds .add (subscriptionId );
0 commit comments