Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #192 from facebook/chore/add-message-when-server-i…
Browse files Browse the repository at this point in the history
…s-down

chore: add message when the server it's not running
  • Loading branch information
eduardocesb authored May 25, 2022
2 parents 2a150b8 + 8d4bbce commit 74113f4
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/js/components/Preview.react.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { Loader, Dimmer, Form, Tab } from 'semantic-ui-react';
import Warnings from './Warnings.react';
import debounce from '../utils/debounce';
import EditorActions from '../data/EditorActions';
import { renderToString } from 'react-dom/server';

import webserver from '../utils/preview-webserver';
import { BrowserWindow } from 'electron';
Expand Down Expand Up @@ -53,6 +54,16 @@ class Preview extends React.Component<Props, State> {
};
}

serverErrorMessage = () => {
return (
<div style={{display: 'flex', alignItems: 'center', fontFamily: 'sans-serif', color: '#ccc', height: '100%'}}>
<p style={{maxWidth: '300px', margin: 'auto', textAlign: 'center'}}>
Webserver error: Please check if the server is running.
</p>
</div>
);
}

previewLoading = () => {
this.setState({ previewLoading: true });
};
Expand Down Expand Up @@ -151,6 +162,15 @@ class Preview extends React.Component<Props, State> {
}
}
};

xhr.onerror = () => {
this.previewFinishedLoading();
this.setState({
errorHtml: renderToString(this.serverErrorMessage()),
});
this.reloadPreview();
};

xhr.open('POST', url.href);
xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
xhr.send(this.getWSURLParams());
Expand Down

0 comments on commit 74113f4

Please sign in to comment.