Skip to content

Commit 7d15cbd

Browse files
committed
move creation of header object into try catch block
1 parent 92b50c4 commit 7d15cbd

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
@@ -259,37 +259,39 @@ export class AppSyncRealTimeSubscriptionHandshakeLink extends ApolloLink {
259259
// Preparing payload for subscription message
260260

261261
const dataString = JSON.stringify(data);
262-
const headerObj = {
263-
...(await this._awsRealTimeHeaderBasedAuth({
264-
apiKey,
265-
appSyncGraphqlEndpoint,
266-
authenticationType,
267-
payload: dataString,
268-
canonicalUri: "",
269-
region,
270-
credentials,
271-
token,
272-
graphql_headers
273-
})),
274-
[USER_AGENT_HEADER]: USER_AGENT
275-
};
262+
let stringToAWSRealTime: string;
276263

277-
const subscriptionMessage = {
278-
id: subscriptionId,
279-
payload: {
280-
data: dataString,
281-
extensions: {
282-
authorization: {
283-
...headerObj
264+
try {
265+
const headerObj = {
266+
...(await this._awsRealTimeHeaderBasedAuth({
267+
apiKey,
268+
appSyncGraphqlEndpoint,
269+
authenticationType,
270+
payload: dataString,
271+
canonicalUri: "",
272+
region,
273+
credentials,
274+
token,
275+
graphql_headers
276+
})),
277+
[USER_AGENT_HEADER]: USER_AGENT
278+
};
279+
280+
const subscriptionMessage = {
281+
id: subscriptionId,
282+
payload: {
283+
data: dataString,
284+
extensions: {
285+
authorization: {
286+
...headerObj
287+
}
284288
}
285-
}
286-
},
287-
type: MESSAGE_TYPES.GQL_START
288-
};
289+
},
290+
type: MESSAGE_TYPES.GQL_START
291+
};
289292

290-
const stringToAWSRealTime = JSON.stringify(subscriptionMessage);
293+
stringToAWSRealTime = JSON.stringify(subscriptionMessage);
291294

292-
try {
293295
await this._initializeWebSocketConnection({
294296
apiKey,
295297
appSyncGraphqlEndpoint,

0 commit comments

Comments
 (0)