A technical walkthrough demonstrating the implementation and testing of an Axios retry mechanism within a Nest.js application. The process includes configuring HTTP modules, emulating server failures with 503 status codes, utilizing Postman for testing, and fine-tuning retry configurations for improved service resilience.
Length 10:37
Captions English (Generated), Spanish (Auto-translated), French (Auto-translated), Korean (Auto-translated), Portuguese (Auto-translated), Vietnamese (Auto-translated) #axios #retry #nest.js #http #resiliency #debugging #software engineering #typescript #postman #backend
0:00 All right, so now let's go ahead and actually test out our new retry 0:04 mechanism. 0:06 For this, we're gonna utilize our upstream 0:08 controller, where we've 0:09 already created the unstable get route here, where we 0:13 have the query parameter that takes in the rate of failed requests 0:17 that we want to emulate. 0:19 And then based off of this probability value, we have a math 0:23 random is less than this fail rate, then we're gonna throw an 0:27 HTTP exception with the upstream is down, and 0:30 importantly, this is going to be a five O three status 0:33 code. 0:34 Now remember back inside of our Axios adapter, 0:39 this is the same default status code that we listened for 0:43 for failure. And additionally, Axios retry 0:47 is retryable error works for all five hundred level errors. 0:51 So both in our custom override case and the default of Axios 0:55 retry, this five O three 0:58 would be retried, of course, if this is an idempotent method, 1:02 which we know it is since it is a get route. 1:05 So both of these conditions will make sure that our Axios retry 1:09 will actually retry when 1:12 this request throws this five O three exception which indicates a 1:15 temporary server error. So now to properly test this, 1:19 I'm gonna add a new get route to our demo controller. 1:23 So this is the controller that we're gonna call from Postman, 1:26 and from 1:26 here we'll then use our Axios adapter to call 1:30 the upstream controller and have that retry functionality built out 1:34 of the box now. 1:37 So I'll launch a new get route here, which we can just call 1:41 this call. 1:43 We'll have async call method that will also take in a query parameter, 1:47 and so 1:47 this will again be the fail rate that will allow us to control the 1:50 level or the rate of failure in the upstream.
The rest of the transcript is for members.
Sign in