AWS S3 Multipart: How to auto-retry requests to the companion server that fail

I am using Uppy with the AWS S3 Multipart plugin and a companion server that my team built to provide the endpoints the plugin needs to perform the multi-part upload.

Our companion server occasionally returns temporary 502 and 504 responses, which instantly causes this code in the plugin to fail, which then causes the entire upload to fail.

Ideally I think it would be best if the plugin used the same auto-retry logic it uses for requests to S3 (to upload file chunk bytes) with requests it makes to the companion server. However, since that is currently not the case, then I would like to provide the retry behavior myself.

I know that the plugin allows the caller to provide custom functions for the various companion server interactions, and perhaps this is how I would accomplish this. But, I would like to write these functions in a way that calls the default implementation provided by the plugin, but wraps it with retry logic, and it’s not clear to me how to do that. I don’t want to end up copy/paste/overriding a lot of logic in the plugin in order to add my retry logic.

Does anyone know if it’s possible to provide a custom function for something like fetching signed URLs for file chunks that calls the plugin’s default implementation? If so, could you please provide a code example showing how to do that? I would also want to do something similar for the other plugin options that override interactions with the companion server. Thanks.