export async function handleSubscriptionError()

in source/console/src/util/CustomUtil.tsx [312:329]


export async function handleSubscriptionError(err: any, subscriptionType: SubscriptionTypes, configureSubscriptionFn: ConfigureSubscriptionFn, delayMS: number) {
  console.error(err);

  const MAX_DELAY_MS = 1000;
  if (delayMS > MAX_DELAY_MS) {
    // Exponential backoff has reached the limit we've defined; reload the page
    window.location.reload();
  } else if (err.error && err.error.errors && err.error.errors[0] && err.error.errors[0].message === 'Connection closed') {
    // An AppSync subscription has lost its connection
    setTimeout(async () => { await configureSubscriptionFn(subscriptionType, delayMS * 2) }, delayMS);
  } else if (delayMS <= MAX_DELAY_MS && err.error && typeof err.error === 'string' && err.error.toLowerCase().includes('disconnected')) {
    // An IoT subscription has lost its connection
    setTimeout(async () => { await configureSubscriptionFn(subscriptionType, delayMS * 2) }, delayMS);
  } else {
    // Otherwise, reload the page
    window.location.reload();
  }
}