A developer implements a configurable Axios retry mechanism within a code editor. The process includes defining retry conditions based on HTTP methods and status codes, establishing custom exponential backoff with jitter to improve system resiliency, and configuring timeout resets for failed requests.
Length 15:46
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #axios #javascript #typescript #retry #fault-tolerance #resiliency #exponential-backoff #jitter #http #programming
0:00 All right, so let's go ahead and start updating our Axios 0:04 retry to actually be fully configurable and 0:08 improve its fault tolerance and resiliency. 0:11 So for this, we're gonna go ahead and open up the options object where we 0:15 can 0:15 further configure Axios retry according to our 0:19 desire. 0:20 So the first thing I'm gonna do is actually get access to 0:24 our underlying retry configuration, which comes from the 0:28 underlying HTTP module options that we know we get passed in 0:33 from the configuration. Remember at the root app module, 0:37 we passed in our configuration object, and so we want to 0:41 access the retry object, which gives us access to those 0:44 overrides from the module provider. 0:47 And now the first thing we'll set is the retries. 0:50 So here we can now access the retries property on the retries 0:54 configuration. And again, this is the number of retries that 0:58 Axios retry will execute before actually 1:02 re-throwing the error. So that's important. 1:04 When Axios retry actually retries the request and it 1:08 succeeds, that just carries on as normal in our app. 1:12 But if we do fail the retry limit here, then we will 1:15 re-throw an actual error back to the caller after we've exceeded 1:19 this value. So by default, that will be three, 1:24 and so we can configure if this is not provided, we'll keep this at 1:28 the default of three. Next up, we have the retry 1:31 condition property. Now, this is a callback function that 1:35 gets passed in the underlying error from Axios. 1:39 So this is Axios error type, and now in this callback, 1:43 we actually return back a simple Boolean 1:48 value, which tells Axios retry whether or not to 1:51 actually retry this error depending on any custom logic we now 1:55 want to implement. Now in our case, we want to provide 1:59 custom behavior to choose when we retry based off of
The rest of the transcript is for members.
Sign in