From 37bfc219df53abf3f938fd9ffb77624963cda475 Mon Sep 17 00:00:00 2001 From: Malte Ulfers Date: Mon, 14 Feb 2022 13:31:26 +0100 Subject: [PATCH] move creation of header object into try catch block --- .../realtime-subscription-handshake-link.ts | 56 ++++++++++--------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts b/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts index 8bc581dd..b0265eea 100644 --- a/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts +++ b/packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts @@ -268,37 +268,39 @@ export class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink { // Preparing payload for subscription message const dataString = JSON.stringify(data); - const headerObj = { - ...(await this._awsRealTimeHeaderBasedAuth({ - apiKey, - appSyncGraphqlEndpoint, - authenticationType, - payload: dataString, - canonicalUri: "", - region, - credentials, - token, - graphql_headers - })), - [USER_AGENT_HEADER]: USER_AGENT - }; + let stringToAWSRealTime: string; - const subscriptionMessage = { - id: subscriptionId, - payload: { - data: dataString, - extensions: { - authorization: { - ...headerObj + try { + const headerObj = { + ...(await this._awsRealTimeHeaderBasedAuth({ + apiKey, + appSyncGraphqlEndpoint, + authenticationType, + payload: dataString, + canonicalUri: "", + region, + credentials, + token, + graphql_headers + })), + [USER_AGENT_HEADER]: USER_AGENT + }; + + const subscriptionMessage = { + id: subscriptionId, + payload: { + data: dataString, + extensions: { + authorization: { + ...headerObj + } } - } - }, - type: MESSAGE_TYPES.GQL_START - }; + }, + type: MESSAGE_TYPES.GQL_START + }; - const stringToAWSRealTime = JSON.stringify(subscriptionMessage); + stringToAWSRealTime = JSON.stringify(subscriptionMessage); - try { await this._initializeWebSocketConnection({ apiKey, appSyncGraphqlEndpoint,