I am integrating a third-party API into my NestJS application to retrieve data and perform certain operations. Occasionally, the API throws a 400 Bad Request error, in which case I need to retry the call after a waiting period of 1 second. What is the best and most efficient way to handle this scenario?
service.ts
async fetchData() {
try {
const response = await axios.get('my-api-irl')
// .. performing some data manipulation with the response
} catch (error) {
// Need to implement retry logic for error status code 400
}
}