Skip to content

Commit

Permalink
Merge pull request #1220 from nbusser/main
Browse files Browse the repository at this point in the history
refactor(ws-response): mutability on response
  • Loading branch information
willfarrell authored Jun 30, 2024
2 parents e862f8d + 9af571b commit 9c55c3f
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions packages/ws-response/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,9 @@ const wsResponseMiddleware = (opts) => {
}

const wsResponseMiddlewareAfter = async (request) => {
normalizeWsResponse(request)
const { response } = request
const normalizedResponse = normalizeWsResponse(request)

if (!response.ConnectionId) return
if (!normalizedResponse.ConnectionId) return

if (!options.awsClientOptions.endpoint && request.event.requestContext) {
options.awsClientOptions.endpoint =
Expand All @@ -43,7 +42,7 @@ const wsResponseMiddleware = (opts) => {
client = await createClient(options, request)
}

const command = new PostToConnectionCommand(response)
const command = new PostToConnectionCommand(normalizedResponse)
await client
.send(command)
.catch((e) => catchInvalidSignatureException(e, client, command))
Expand All @@ -68,7 +67,6 @@ const normalizeWsResponse = (request) => {
response = { Data: response }
}
response.ConnectionId ??= request.event.requestContext?.connectionId
request.response = response
return response
}

Expand Down

0 comments on commit 9c55c3f

Please sign in to comment.