Skip to content

Commit 37bfc21

Browse files
committed
move creation of header object into try catch block
1 parent 6132938 commit 37bfc21

File tree

1 file changed

+29
-27
lines changed

1 file changed

+29
-27
lines changed

packages/aws-appsync-subscription-link/src/realtime-subscription-handshake-link.ts

Lines changed: 29 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -268,37 +268,39 @@ export class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink {
268268
// Preparing payload for subscription message
269269

270270
const dataString = JSON.stringify(data);
271-
const headerObj = {
272-
...(await this._awsRealTimeHeaderBasedAuth({
273-
apiKey,
274-
appSyncGraphqlEndpoint,
275-
authenticationType,
276-
payload: dataString,
277-
canonicalUri: "",
278-
region,
279-
credentials,
280-
token,
281-
graphql_headers
282-
})),
283-
[USER_AGENT_HEADER]: USER_AGENT
284-
};
271+
let stringToAWSRealTime: string;
285272

286-
const subscriptionMessage = {
287-
id: subscriptionId,
288-
payload: {
289-
data: dataString,
290-
extensions: {
291-
authorization: {
292-
...headerObj
273+
try {
274+
const headerObj = {
275+
...(await this._awsRealTimeHeaderBasedAuth({
276+
apiKey,
277+
appSyncGraphqlEndpoint,
278+
authenticationType,
279+
payload: dataString,
280+
canonicalUri: "",
281+
region,
282+
credentials,
283+
token,
284+
graphql_headers
285+
})),
286+
[USER_AGENT_HEADER]: USER_AGENT
287+
};
288+
289+
const subscriptionMessage = {
290+
id: subscriptionId,
291+
payload: {
292+
data: dataString,
293+
extensions: {
294+
authorization: {
295+
...headerObj
296+
}
293297
}
294-
}
295-
},
296-
type: MESSAGE_TYPES.GQL_START
297-
};
298+
},
299+
type: MESSAGE_TYPES.GQL_START
300+
};
298301

299-
const stringToAWSRealTime = JSON.stringify(subscriptionMessage);
302+
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
300303

301-
try {
302304
await this._initializeWebSocketConnection({
303305
apiKey,
304306
appSyncGraphqlEndpoint,

0 commit comments

Comments
 (0)