Change the retry on error

This procedure shows you how to change the variables related to the retry attempts on network error. It involves setting network theme variables.

About this task

When there is a network/HTTP error, the GBC will retry sending an HTTP request before stopping the application. You can customize this behavior by checking for specified HTTP status codes and/or changing the retry timeout. To do this you must set the relevant network theme variables:
  • In the $theme-network-retry-on-error variable, provide a list of HTTP status codes. If you set this variable to the HTTP status codes [502, 504], when the application receives a 502 or 504 code in response to a request, the GBC will send the HTTP request again. For information on the full range of HTTP status codes see RFC 2616.
  • The number of times the request can be resent is set by the $theme-network-retry-timeout variable. The default value is [1, 1, 1, 2, 2, 2, 4, 4, 4]. For more information on the default value, see HTTP retries.

    This feature increases the time required for the detection of invalid hosts or dead servers. For example, if you set this variable to [1, 5, 10], the GBC will try a maximum of 3 times to send the HTTP request. The first retry is after 1 second, then if it still fails to get a response, it retries after 5 seconds, and retries again after 10 seconds.

Before you begin

This procedure assumes you are comfortable updating theme parts and themes. For the basic principles behind themes and theme parts, see How customization works. For instructions about adding and modifying themes and theme parts, see Working with themes. For information about the underlying GBC infrastructure and its components, see Theme reference.

In this example, you will customize the GBC to resend requests on network error before stopping the application.

  1. Identify the theme part you plan to update. If you are creating a new theme part, prepare the directory.
  2. In the theme part, open the theme.scss.json file in a text editor.
  3. To edit the setttings used by the network retry on error, edit the $theme-network-retry-on-error and $theme-network-retry-timeout variables. For example:
    // in theme.scss.json
    {
      ...
      "theme-network-retry-on-error":[502, 504],
      "theme-network-retry-timeout":[1, 5, 10],
      ...
    }
  4. If you created a new theme part, add it to one or more themes.
  5. Save your changes and rebuild your customization using gbc build:
    $ gbc build --customization customization-project-dir
  6. Test that your changes work as expected.
    To test the retry-on-error, you must open the browser developer tools and do either of the following:
    • Check the HTTP status in the output of the network section.
    • Look in the browser console for HTTP requests.
    If HTTP requests are being retried, they will appear with the same URL and arguments.

    If your tests do not behave as expected, ensure you are using your newly-built custom GBC. Depending on your development environment, you may need to package and deploy a custom GBC client. For information on which customization and theme you are using, see Selecting customizations and themes.