Skip to content
This repository has been archived by the owner on Nov 14, 2022. It is now read-only.

Commit

Permalink
Add error handling to agent actions
Browse files Browse the repository at this point in the history
Signed-off-by: Karim Stekelenburg <karim@animo.id>
  • Loading branch information
karimStekelenburg committed Jan 14, 2021
1 parent 7a0c537 commit 1e7c3b5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
6 changes: 5 additions & 1 deletion src/agent/AgentProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,11 @@ const AgentProvider = (props: AgentContextProps) => {
}

useEffect(() => {
initAgent()
try {
initAgent()
} catch (e) {
console.warn(e)
}
}, [])

return <AgentContext.Provider value={{ loading, agent }}>{props.children}</AgentContext.Provider>
Expand Down
3 changes: 1 addition & 2 deletions src/agent/transporters/HTTPOutboundTransporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ class HttpOutboundTransporter implements OutboundTransporter {
})

const data = await response.text()

const wireMessage = JSON.parse(data)
return wireMessage
} else {
Expand All @@ -34,7 +33,7 @@ class HttpOutboundTransporter implements OutboundTransporter {
})
}
} catch (e) {
// console.log('error sending message', JSON.stringify(e));
console.error('error sending message', e)
throw e
}
}
Expand Down
29 changes: 13 additions & 16 deletions src/agent/transporters/PollingInboundTransporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,19 @@ class PollingInboundTransporter implements InboundTransporter {
}

public async registerMediator(agent: Agent): Promise<void> {
console.log('fetching mediator url')
const mediatorUrl = agent.getMediatorUrl()
console.log(`got mediator url: ${mediatorUrl}, fetching response`)
const mediatorInvitationUrlResponse = await axios.get(`${mediatorUrl}/invitation`)
console.log(`got invite response: ${mediatorInvitationUrlResponse}`)
const response = await axios.get(`${mediatorUrl}/`)
console.log(`got response: ${response}`)
const { verkey: mediatorVerkey } = response.data
await agent.routing.provision({
verkey: mediatorVerkey,
invitationUrl: mediatorInvitationUrlResponse.data,
})
this.pollDownloadMessages(agent)
try {
const mediatorUrl = agent.getMediatorUrl()
const mediatorInvitationUrlResponse = await axios.get(`${mediatorUrl}/invitation`)
const response = await axios.get(`${mediatorUrl}/`)
const { verkey: mediatorVerkey } = response.data
await agent.routing.provision({
verkey: mediatorVerkey,
invitationUrl: mediatorInvitationUrlResponse.data,
})
this.pollDownloadMessages(agent)
} catch (error) {
console.warn(error)
}
}

private pollDownloadMessages(agent: Agent): void {
Expand All @@ -35,9 +35,6 @@ class PollingInboundTransporter implements InboundTransporter {
const messages = [...downloadedMessages]
while (messages && messages.length > 0) {
const message = messages.shift()
console.log('INBOUND TRANSPORT: RECEIVED MESSAGE')
console.log(message)

await agent.receiveMessage(message)
}
},
Expand Down

0 comments on commit 1e7c3b5

Please sign in to comment.