Using ModResponse to simulate edge cases

Problems

If you are creating a static page, you can be sure that the content will always be the same. Except for the occasional internet connectivity issue, there is not much you will need to worry about.

However, if you are building a dynamic page, where you need to retrieve data from an API response at runtime, then things can get more complicated. You may get API response that you did not expect (for example, it may return a very long string, or certain fields may be missing, etc.) Your API request may time out. Or it may return a bad request or a server error. A lot of possible error scenarios can happen. If your website is receiving millions of users, even if these are edge cases, they will still be seen by many users.

Simulating edge cases

Obviously, you can update your server to return fake data to simulate the edge cases that you are testing against. You can make your server turn corrupted data, or add some delays to make it timeout, or just simply fail with an error status code. These will require code changes that are built into your server, and may slow down your development cycle.

Using ModResponse, you can simulate these edge cases scenarios within seconds without having to update your codes! You can use ModResponse to return fake data, add delays, simulate error status code, and even simulate network errors.

Modify HTTP response body
  • Open ModResponse, then click on , and select Replay response
  • Adjust the URL to the API URL that returns the data that you would like to change. Note that you can click on button to toggle regex URL matching mode.
  • Now navigate to the page where the API request happens. This will allow ModResponse to record the API response.
  • Now open ModResponse again, and , then click on the cached URL. This will open up a dialog that allow you to adjust the HTTP response body.
  • Edit the HTTP response body as needed, then click Save.
  • Refresh your page, and it should be getting the modified HTTP response.
Modify HTTP status code
  • Follow the steps above to record the API that you would like to edit on ModResponse.
  • Now open ModResponse again, then click on the cached URL. This will open up a dialog that allow you to adjust the HTTP response. Edit the HTTP status code as needed, then click Save.
  • Refresh your page, and you should be getting the modified HTTP status code.
Simulate slow network
Option 1: Using real API response
  • Open ModResponse, then click on , and select Delay request
  • Adjust the URL to the API URL that returns the data that you would like to change. Note that you can click on button to toggle regex URL matching mode.
  • Adjust the delay as needed. For example, if you want the request to take more than 10 seconds, then enter 10000.
  • Refresh your page, and the HTTP request will now be slowed down as you have configured.
Option 2: Using replay API response
  • If you already have a replay response or other behaviors in ModResponse, you can click on button on the right side of the row to add additional delays.
  • Adjust the delay as needed. For example, if you want the request to take more than 10 seconds, then enter 10000.
  • Refresh your page, and the HTTP request will now be slowed down as you have configured.
Simulate network error
  • Open ModResponse, then click on , and select Simulate network error
  • Adjust the URL to the API URL that returns the data that you would like to change. Note that you can click on button to toggle regex URL matching mode.
  • Adjust the error reason as needed.
  • Refresh your page, and the HTTP request will now return the error that you have configured.