SAP / cloud-sdk-js

Use the SAP Cloud SDK for JavaScript / TypeScript to reduce development effort when building applications on SAP Business Technology Platform that communicate with SAP solutions and services such as SAP S/4HANA Cloud, SAP SuccessFactors, and many others.
Apache License 2.0
161 stars 55 forks source link

Query with retry in SAP Cloud SDK resilience #4835

Closed shankarigr closed 1 month ago

shankarigr commented 1 month ago

Hi,

I have a nestjs project which fetches business partners from s4hana cloud which is working fine. Now I wanted to implement a retry pattern to the existing code.

So, I added the below code

const response =  await businessPartnerApi.requestBuilder().getAll()
        .select(
              businessPartnerApi.schema.BUSINESS_PARTNER,
              businessPartnerApi.schema.FIRST_NAME,
              businessPartnerApi.schema.LAST_NAME
        ).top(5)
        .middleware(retry(4))
        .execute({
            url: '<url>'
         })
         .catch(error => {
                throw new HttpException(`Failed to get business partners - ${error.message}`, 500);
          });

I could see, in this case I am getting a timeout error after sometime.

If I replace retry with timeout, I am able to see the desired response. But with retry I am not. Can someone explain how this works and is there any code modifications required from my side?

Regards, Shankari G R

tomfrenken commented 1 month ago

Hi Shankari, we've documented the order in which the middelwares are executed here. Also, the retry increases the time between retries continuously, the 4th retry will already take around 8 seconds, which clashes with the default of the underlying HTTP client's timeout, which is 10 seconds.

Therefore, if you want to have 4 retries, you need to increase the timeout as well, I suggest you use our default resilience package for that.

tomfrenken commented 1 month ago

If this did not resolve your issue, feel free to re-open it.