Skip to content

Commit

Permalink
refactor: add check to WsOutboundTransport
Browse files Browse the repository at this point in the history
Signed-off-by: annelein <[email protected]>
  • Loading branch information
Annelein committed Feb 14, 2022
1 parent addba6c commit d90e635
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/core/src/transport/WsOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type WebSocket from 'ws'
import { AgentConfig } from '../agent/AgentConfig'
import { EventEmitter } from '../agent/EventEmitter'
import { AriesFrameworkError } from '../error/AriesFrameworkError'
import { isValidJweStucture } from '../utils'
import { Buffer } from '../utils/buffer'

import { TransportEventTypes } from './TransportEventTypes'
Expand Down Expand Up @@ -101,7 +102,13 @@ export class WsOutboundTransport implements OutboundTransport {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
private handleMessageEvent = (event: any) => {
this.logger.trace('WebSocket message event received.', { url: event.target.url, data: event.data })
const payload = JSON.parse(Buffer.from(event.data).toString('utf-8'))
const responseMessage = Buffer.from(event.data).toString('utf-8')
if (!isValidJweStucture(responseMessage)) {
throw new Error(
`Received a response from the other agent but the structure of the incoming message is not a DIDComm message: ${responseMessage}`
)
}
const payload = JSON.parse(responseMessage)
this.logger.debug('Payload received from mediator:', payload)
this.agent.receiveMessage(payload)
}
Expand Down

0 comments on commit d90e635

Please sign in to comment.