I hope you will forgive the beginners question, I'm trying to implement a simple retry policy for an api call using node-fetch
This is being added to an existing repo using TypeScript so I'm using this also, hence the data definitions.
async checkStatus(custId: string, expectedStatus: string) { const response = await fetch( `${'env.API_URL'}/api/customer/applications/${custId}`, { method: 'GET', headers: headers, }, ) expect(response.status, "Response status should be 200").to.be.equal(200) const resp = await response.json() expect(resp.status).to.contain(expectedStatus) return resp.status;}
I am calling it like so
await this.checkApplicationStatus(custId, 'NEW')await this.checkApplicationStatus(custId, 'EXISTING')//and so forth
Is there a neat way of retrying based on an unexpected expectedStatus
?
Again, I appreciate there may be many examples out there but as a beginner, I am struggling to see a good/best-practice approach so looking for someone to provide an example. I don't need to use Chai assertions, this was just my first attempt.
TIA