Skip to content

Commit

Permalink
fix(core): do not throw error on timeout in http
Browse files Browse the repository at this point in the history
Signed-off-by: Timo Glastra <[email protected]>
  • Loading branch information
TimoGlastra committed Nov 1, 2021
1 parent e50b821 commit db6ef97
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions packages/core/src/transport/HttpOutboundTransport.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,19 +46,33 @@ export class HttpOutboundTransport implements OutboundTransport {
const abortController = new AbortController()
const id = setTimeout(() => abortController.abort(), 15000)

const response = await this.fetch(endpoint, {
method: 'POST',
body: JSON.stringify(payload),
headers: { 'Content-Type': this.agentConfig.didCommMimeType },
signal: abortController.signal,
})
clearTimeout(id)

const responseMessage = await response.text()
let response
let responseMessage
try {
response = await this.fetch(endpoint, {
method: 'POST',
body: JSON.stringify(payload),
headers: { 'Content-Type': this.agentConfig.didCommMimeType },
signal: abortController.signal,
})
clearTimeout(id)
responseMessage = await response.text()
} catch (error) {
// Request is aborted after 15 seconds, but that doesn't necessarily mean the request
// went wrong. ACA-Py keeps the socket alive until it has a response message. So we assume
// that if the error was aborted and we had return routing enabled, we should ignore the error.
if (error.name == 'AbortError' && outboundPackage.responseRequested) {
this.logger.debug(
'Request was aborted due to timeout. Not throwing error due to return routing on sent message'
)
} else {
throw error
}
}

// TODO: do we just want to ignore messages that were returned if we didn't request it?
// TODO: check response header type (and also update inbound transports to use the correct headers types)
if (responseMessage) {
if (response && responseMessage) {
this.logger.debug(`Response received`, { responseMessage, status: response.status })

try {
Expand Down

0 comments on commit db6ef97

Please sign in to comment.