Skip to content

Commit e375c5b

Browse files
committed
Merge pull request #26 from ParsePlatform/better-error-messages
Better error messages for config issues.
2 parents 74b7e6b + e8112ce commit e375c5b

File tree

4 files changed

+27
-10
lines changed

4 files changed

+27
-10
lines changed

Parse-Dashboard/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,25 @@
55
* This source code is licensed under the license found in the LICENSE file in
66
* the root directory of this source tree.
77
*/
8+
var jsonFile = require('json-file-plus');
89
var express = require('express');
910
var app = express();
1011

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

1415
app.get('/parse-dashboard-config.json', function(req, res) {
15-
res.sendFile(__dirname + '/parse-dashboard-config.json');
16+
jsonFile(__dirname + '/parse-dashboard-config.json')
17+
.then(config => res.json(config.data))
18+
.catch(error => {
19+
if (error instanceof SyntaxError) {
20+
res.send({ success: false, error: 'Your parse-dashboard-config.json file contains invalid JSON.' });
21+
} else if (error.code === 'ENOENT') {
22+
res.send({ success: false, error: 'Your parse-dashboard-config.json file is missing.' });
23+
} else {
24+
res.send({ success: false, error: 'There was a problem with your parse-dashboard-config.json file.' });
25+
}
26+
});
1627
});
1728

1829
// For every other request, go to index.html. Let client-side handle the rest.

dashboard/Apps/AppsIndex.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@
77
*/
88
@import 'stylesheets/globals.scss';
99

10+
.loadingError {
11+
font-size: 58px;
12+
color: #ffffff;
13+
}
14+
1015
.index {
1116
padding: 38px 30px;
1217
background: #1e3b4d;
@@ -105,7 +110,7 @@
105110
margin: 14px 0;
106111
padding: 0 9px;
107112
height: 74px;
108-
113+
109114
&:hover{
110115
background: #172C3B;
111116
}

dashboard/Dashboard.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ class Dashboard extends React.Component {
8787
}
8888

8989
componentDidMount() {
90-
let promise = get('/parse-dashboard-config.json');
91-
promise.then(({ apps }) => {
90+
get('/parse-dashboard-config.json').then(({ apps }) => {
9291
apps.forEach(app => {
9392
if (app.serverURL.startsWith('https://api.parse.com/1')) {
9493
//api.parse.com doesn't have feature availability endpoint, fortunately we know which features
@@ -181,11 +180,11 @@ class Dashboard extends React.Component {
181180
}
182181
});
183182
this.setState({ configLoadingState: AsyncStatus.SUCCESS });
184-
}).fail(error => {
185-
if (typeof error === 'string') {
186-
this.setState({ configLoadingError: 'Your parse-dashboard-config.json file contains invalid JSON.' });
187-
}
188-
this.setState({ configLoadingState: AsyncStatus.FAILED });
183+
}).fail(({ error }) => {
184+
this.setState({
185+
configLoadingError: error,
186+
configLoadingState: AsyncStatus.FAILED
187+
});
189188
});
190189
}
191190

@@ -200,7 +199,8 @@ class Dashboard extends React.Component {
200199
<div className={styles.cloud}>
201200
<Icon width={110} height={110} name='cloud-surprise' fill='#1e3b4d' />
202201
</div>
203-
<div style={{fontSize: '58px', color: '#ffffff'}}>{this.state.configLoadingError}</div>
202+
{/* use non-breaking hyphen for the error message to keep the filename on one line */}
203+
<div className={styles.loadingError}>{this.state.configLoadingError.replace(/-/g, '\u2011')}</div>
204204
</div>
205205
</div>
206206
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"express": "^4.13.4",
66
"history": "~1.9.1",
77
"immutable": "~3.7.5",
8+
"json-file-plus": "^3.2.0",
89
"marked": "^0.3.5",
910
"parse": "1.6.14",
1011
"prismjs": "~1.2.0",

0 commit comments

Comments
 (0)