Skip to content

Better error messages for config issues. #26

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 1, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion Parse-Dashboard/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,25 @@
* This source code is licensed under the license found in the LICENSE file in
* the root directory of this source tree.
*/
var jsonFile = require('json-file-plus');
var express = require('express');
var app = express();

// Serve public files.
app.use(express.static('Parse-Dashboard/public'));

app.get('/parse-dashboard-config.json', function(req, res) {
res.sendFile(__dirname + '/parse-dashboard-config.json');
jsonFile(__dirname + '/parse-dashboard-config.json')
.then(config => res.json(config.data))
.catch(error => {
if (error instanceof SyntaxError) {
res.send({ success: false, error: 'Your parse-dashboard-config.json file contains invalid JSON.' });
} else if (error.code === 'ENOENT') {
res.send({ success: false, error: 'Your parse-dashboard-config.json file is missing.' });
} else {
res.send({ success: false, error: 'There was a problem with your parse-dashboard-config.json file.' });
}
});
});

// For every other request, go to index.html. Let client-side handle the rest.
Expand Down
7 changes: 6 additions & 1 deletion dashboard/Apps/AppsIndex.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@
*/
@import 'stylesheets/globals.scss';

.loadingError {
font-size: 58px;
color: #ffffff;
}

.index {
padding: 38px 30px;
background: #1e3b4d;
Expand Down Expand Up @@ -105,7 +110,7 @@
margin: 14px 0;
padding: 0 9px;
height: 74px;

&:hover{
background: #172C3B;
}
Expand Down
16 changes: 8 additions & 8 deletions dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class Dashboard extends React.Component {
}

componentDidMount() {
let promise = get('/parse-dashboard-config.json');
promise.then(({ apps }) => {
get('/parse-dashboard-config.json').then(({ apps }) => {
apps.forEach(app => {
if (app.serverURL.startsWith('https://api.parse.com/1')) {
//api.parse.com doesn't have feature availability endpoint, fortunately we know which features
Expand Down Expand Up @@ -181,11 +180,11 @@ class Dashboard extends React.Component {
}
});
this.setState({ configLoadingState: AsyncStatus.SUCCESS });
}).fail(error => {
if (typeof error === 'string') {
this.setState({ configLoadingError: 'Your parse-dashboard-config.json file contains invalid JSON.' });
}
this.setState({ configLoadingState: AsyncStatus.FAILED });
}).fail(({ error }) => {
this.setState({
configLoadingError: error,
configLoadingState: AsyncStatus.FAILED
});
});
}

Expand All @@ -200,7 +199,8 @@ class Dashboard extends React.Component {
<div className={styles.cloud}>
<Icon width={110} height={110} name='cloud-surprise' fill='#1e3b4d' />
</div>
<div style={{fontSize: '58px', color: '#ffffff'}}>{this.state.configLoadingError}</div>
{/* use non-breaking hyphen for the error message to keep the filename on one line */}
<div className={styles.loadingError}>{this.state.configLoadingError.replace(/-/g, '\u2011')}</div>
</div>
</div>
}
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"express": "^4.13.4",
"history": "~1.9.1",
"immutable": "~3.7.5",
"json-file-plus": "^3.2.0",
"marked": "^0.3.5",
"parse": "1.6.14",
"prismjs": "~1.2.0",
Expand Down