From 71aa76d145812170d2f9d8e3110ef907427e08ef Mon Sep 17 00:00:00 2001 From: Rafael Juliano Date: Thu, 16 Jul 2020 13:17:38 -0400 Subject: [PATCH] fix(api) Fix tests broken by PR #599 (#647) * fix(api) Fix tests broken by PR #599 * Move buildSubscriptionUrl to its original place --- .../api/aws/SubscriptionEndpoint.java | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java b/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java index f05d3cec45..9a39a73622 100644 --- a/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java +++ b/aws-api/src/main/java/com/amplifyframework/api/aws/SubscriptionEndpoint.java @@ -68,7 +68,6 @@ final class SubscriptionEndpoint { private final GraphQLResponse.Factory responseFactory; private final TimeoutWatchdog timeoutWatchdog; private final Set pendingSubscriptionIds; - private final String subscriptionUrl; private final OkHttpClient okHttpClient; private WebSocket webSocket; private AmplifyWebSocketListener webSocketListener; @@ -84,7 +83,6 @@ final class SubscriptionEndpoint { this.authorizer = Objects.requireNonNull(authorizer); this.timeoutWatchdog = new TimeoutWatchdog(); this.pendingSubscriptionIds = Collections.synchronizedSet(new HashSet<>()); - this.subscriptionUrl = buildConnectionRequestUrl(); this.okHttpClient = new OkHttpClient.Builder() .addNetworkInterceptor(UserAgentInterceptor.using(UserAgent::string)) .retryOnConnectionFailure(true) @@ -107,10 +105,16 @@ synchronized void requestSubscription( // force a new connection to be created. if (webSocketListener == null || webSocketListener.isDisconnectedState()) { webSocketListener = new AmplifyWebSocketListener(); - webSocket = okHttpClient.newWebSocket(new Request.Builder() - .url(subscriptionUrl) - .addHeader("Sec-WebSocket-Protocol", "graphql-ws") - .build(), webSocketListener); + try { + webSocket = okHttpClient.newWebSocket(new Request.Builder() + .url(buildConnectionRequestUrl()) + .addHeader("Sec-WebSocket-Protocol", "graphql-ws") + .build(), webSocketListener); + } catch (ApiException apiException) { + onSubscriptionError.accept(apiException); + return; + } + } final String subscriptionId = UUID.randomUUID().toString(); pendingSubscriptionIds.add(subscriptionId);