connectionlost.ts 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // Copyright (c) Jupyter Development Team.
  2. // Distributed under the terms of the Modified BSD License.
  3. import { showErrorMessage } from '@jupyterlab/apputils';
  4. import { ServerConnection, ServiceManager } from '@jupyterlab/services';
  5. import { IConnectionLost } from './tokens';
  6. /**
  7. * A default connection lost handler, which brings up an error dialog.
  8. */
  9. export const ConnectionLost: IConnectionLost = async function(
  10. manager: ServiceManager.IManager,
  11. err: ServerConnection.NetworkError
  12. ): Promise<void> {
  13. if (Private.showingError) {
  14. return;
  15. }
  16. Private.showingError = true;
  17. const title = 'Server Connection Error';
  18. const networkMsg =
  19. 'A connection to the Jupyter server could not be established.\n' +
  20. 'JupyterLab will continue trying to reconnect.\n' +
  21. 'Check your network connection or Jupyter server configuration.\n';
  22. return showErrorMessage(title, { message: networkMsg }).then(() => {
  23. Private.showingError = false;
  24. });
  25. };
  26. /**
  27. * A namespace for module private functionality.
  28. */
  29. namespace Private {
  30. /**
  31. * Whether the connection lost error is currently being shown.
  32. */
  33. export let showingError = false;
  34. }