WP-API / node-wpapi

An isomorphic JavaScript client for the WordPress REST API
http://wp-api.org/node-wpapi/
MIT License
1.68k stars 190 forks source link

Adding superagent-retry-delay package to the native library #488

Open anders-naslund opened 3 years ago

anders-naslund commented 3 years ago

I'm updating several thousand posts using this API over a WAN connection and received a lot of timeouts in the requests using the native superagent implementations. One way on solving this was to implement a "retry/timeout layer" in the application itself but then I found another package that's an extension of the superagent that is being used. https://www.npmjs.com/package/superagent-retry-delay

In order to make use of this additional package only minor changes in the wpapi/lib/http-transport.js file is needed. Added require('superagent-retry-delay')(agent); just after the row const agent = require( 'superagent' ); Changed all "requests" rows from: let request = _auth( agent.put( url ), .... to: let request = _auth( agent.get( url ).retry(5, 3600000, [401, 404]),..... It works like a charm and I don't need to have logic in the application itself. Is there any chance that this could be added to the native WP-API?

theabhinavdas commented 3 years ago

Love this, I'll give it a shot. I'm facing issues while bulk posting as well.