Skip to content

Commit abcd436

Browse files
author
Dario Segura
committed
[ALL] Much better error handling
1 parent e8f79ea commit abcd436

File tree

12 files changed

+148
-48
lines changed

12 files changed

+148
-48
lines changed

server/lyrics/Lyrics.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,10 @@ function findLyrics(song, artist, duration) {
1717
}
1818
// cascade if needed
1919
resolve(lyrics);
20+
})
21+
.catch(reason => {
22+
log(reason);
23+
return null;
2024
});
2125
// Xiami.search(song, artist, duration);
2226
// NetEase.search(song, artist, duration);

src/frontend/header/SearchBar.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,10 @@ export class SearchBar {
6363
}
6464
} else if (value()) {
6565
Service.activeService().searchHints(value()).then(result => {
66-
matches(result.terms);
67-
m.redraw();
66+
if (result) {
67+
matches(result.terms);
68+
m.redraw();
69+
}
6870
});
6971
} else {
7072
matches([]);

src/frontend/routes/Home.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ export class Home extends Layout {
2828
]),
2929
m('.search-loading-text', 'Loading...'),
3030
]);
31+
} else if (this.mContent.hasOwnProperty('error')) {
32+
return m('.search-full-centered', [
33+
m('.search-loading-text', this.mContent.error),
34+
]);
3135
}
3236

3337
return this.mContent.map(row => {
@@ -57,7 +61,13 @@ export class Home extends Layout {
5761
_loadContent() {
5862
if (!this.mContent && Service.activeService()) {
5963
Service.activeService().getHomeContent().then(content => {
60-
this.mContent = content;
64+
if (content) {
65+
this.mContent = content;
66+
} else {
67+
this.mContent = {
68+
error: 'An error occurred loading the home content, please try again later.',
69+
};
70+
}
6171
m.redraw();
6272
});
6373
}

src/frontend/routes/NowPlaying.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ import {Layout} from '../Layout';
33
import {List} from 'polythene-mithril';
44
import {SongItem} from '../components/SongItem';
55
import {MediaManager} from '../../service/MediaManager';
6-
import {Buttons, GeneralEvents, PlaybackEvents} from '../Events';
7-
import {EventCenter} from '../../core/EventCenter';
6+
import {Buttons} from '../Events';
87

98
export class NowPlaying extends Layout {
109
constructor(/* vnode */) {

src/frontend/routes/Playlist.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,7 @@ export class Playlist extends Layout {
7979
const service = Service.activeService(serviceName ? serviceName : null);
8080
if (service && playlistID) {
8181
this.mPlaylist = null;
82-
let p;
83-
p = service.getPlaylistInfo(playlistID);
84-
p.then(result => {
82+
service.getPlaylistInfo(playlistID).then(result => {
8583
if (result) {
8684
this.mPlaylist = result;
8785
} else {

src/frontend/routes/Search.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ export class Search extends Layout {
3939
]);
4040
}
4141

42+
if (this.mSearchResults.hasOwnProperty('error')) {
43+
return m('.search-result-header', this.mSearchResults.error);
44+
}
45+
4246
let hasContent = false;
4347
Object.keys(this.mSearchResults).forEach(key => {
4448
hasContent = this.mSearchResults[key] || hasContent;
@@ -66,7 +70,13 @@ export class Search extends Layout {
6670
const service = Service.activeService();
6771
this.mSearchResults = null;
6872
service.search(searchTerm, 21).then(result => {
69-
this.mSearchResults = result;
73+
if (result) {
74+
this.mSearchResults = result;
75+
} else {
76+
this.mSearchResults = {
77+
error: 'An error occurred, please try again later',
78+
};
79+
}
7080
m.redraw();
7181
});
7282
}

src/frontend/routes/Splash.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ export class Splash {
7474
document.addEventListener('musickitloaded', () => {
7575
AppleService.instance().init('devtoken.jwt', 'Jukebox by Julyee', '1.0.0').then(() => {
7676
m.redraw();
77+
}).catch(reason => {
78+
console.error(reason); // eslint-disable-line
79+
window.MusicKit = null;
7780
});
7881
});
7982
}
@@ -273,6 +276,9 @@ export class Splash {
273276
} else {
274277
Dialog.hide();
275278
}
279+
}).catch(reason => {
280+
console.error(reason); // eslint-disable-line
281+
Dialog.hide();
276282
});
277283

278284
Dialog.show(loadingDialog({
@@ -285,7 +291,7 @@ export class Splash {
285291
} else {
286292
Dialog.show(WarningDialog.get(
287293
'Error',
288-
'Could not connect to the specified server.',
294+
'Could not connect to Apple Music.',
289295
'Got it'
290296
));
291297
}

src/frontend/utils/QRScannerWorker.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ const source =
3939
alignpat + '\n' +
4040
databr;
4141

42-
43-
4442
const blob = new Blob([source], {type: 'application/javascript'});
4543

4644
export const QRWorkerURL = URL.createObjectURL(blob);

src/index.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,8 @@ async function main() {
99

1010
document.addEventListener('DOMContentLoaded', async () => {
1111
console.log(webRTCAdapter); // eslint-disable-line
12-
await main();
12+
await main().catch(reason => {
13+
console.error('[JUKEBOX] Unhandled ERROR: %o', reason); // eslint-disable-line
14+
return null;
15+
});
1316
}, true);

src/service/MusicQueue.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import IBindable from '../core/IBindable';
2-
import {EventCenter} from '../core/EventCenter';
32

43
export class MusicQueue extends IBindable {
54
constructor() {
@@ -67,6 +66,10 @@ export class MusicQueue extends IBindable {
6766
.then(lyrics => {
6867
this.mLyricsCache[key] = lyrics;
6968
return lyrics;
69+
}).catch(reason => {
70+
console.error(reason); // eslint-disable-line
71+
delete this.mLyricsCache[key];
72+
return null;
7073
});
7174
}
7275

0 commit comments

Comments
 (0)