Skip to content

Commit

Permalink
fixing double consumption of res
Browse files Browse the repository at this point in the history
  • Loading branch information
juraj.bacovcin committed Dec 20, 2024
1 parent 2cac157 commit ad37b59
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/connector/tatum.connector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,14 +115,15 @@ export class TatumConnector {
return await res.blob()
}
const response = await res.json()
if (!response?.error) {
return response
if (response?.error) {
return await this.retry(url, request, responseBody, retry)
}
return response
}

// Retry only in case of 5xx error
if (res.status >= 500 && res.status < 600) {
return await this.retry(url, request, res, retry)
return await this.retry(url, request, responseBody, retry)
}

throw responseBody
Expand Down Expand Up @@ -180,7 +181,7 @@ export class TatumConnector {
private async retry<RESPONSE>(
url: string,
request: RequestInit,
response: Response,
responseBody: string,
retry: number,
): Promise<RESPONSE | Blob | undefined> {
const { retryDelay, retryCount } = Container.of(this.id).get(CONFIG)
Expand All @@ -190,7 +191,7 @@ export class TatumConnector {
message: `Not retrying the request - no max retry count defined`,
data: { url, requestBody: request.body },
})
return Promise.reject(await response.text())
return Promise.reject(responseBody)
}

if (retry >= retryCount) {
Expand All @@ -199,7 +200,7 @@ export class TatumConnector {
message: `Not retrying the request for the '${retry}' time - exceeded max retry count ${retryCount}: `,
data: { url, requestBody: request.body },
})
return Promise.reject(await response.text())
return Promise.reject(responseBody)
}

retry++
Expand Down

0 comments on commit ad37b59

Please sign in to comment.