From 7ac34194f5882d228724c20ba22d5abc9e1e40e4 Mon Sep 17 00:00:00 2001 From: theADAMJR Date: Tue, 15 Dec 2020 17:41:36 +0000 Subject: [PATCH] Player UI #7 - Show Errors --- dashboard/assets/js/music/html-music-wrapper.js | 6 +++++- dashboard/assets/js/music/music-wrapper.js | 11 +++++++++-- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dashboard/assets/js/music/html-music-wrapper.js b/dashboard/assets/js/music/html-music-wrapper.js index 6ab9511..06db6fd 100644 --- a/dashboard/assets/js/music/html-music-wrapper.js +++ b/dashboard/assets/js/music/html-music-wrapper.js @@ -2,7 +2,11 @@ class HTMLMusicWrapper { #music; set apiError(error) { - console.log(error); + if (!error) + return $('#musicAPIError').addClass('d-none'); + + $('#musicAPIError').removeClass('d-none'); + $('#musicAPIError').text(error.message ?? 'Unknown error.'); } constructor(musicClient) { diff --git a/dashboard/assets/js/music/music-wrapper.js b/dashboard/assets/js/music/music-wrapper.js index 37e9ccd..4ef339c 100644 --- a/dashboard/assets/js/music/music-wrapper.js +++ b/dashboard/assets/js/music/music-wrapper.js @@ -16,16 +16,23 @@ class MusicWrapper { return json; } catch (error) { this.#html.apiError = error; + throw error; } } async play(query) { - await this.#fetch(`play?q=${query}`); + try { + await this.#fetch(`play?q=${query}`); + this.#html.apiError = null; + } catch {} await this.updateList(); } async stop() { - await this.#fetch(`stop`); + try { + await this.#fetch(`stop`); + this.#html.apiError = null; + } catch {} await this.updateList(); }