fuzzyworld

hawk / commit

Log and report error if it's not possible to play the track.

0857dbd1a6122ef91d6c03671303c717bde6544b · Pavel Safronov · 2023-10-17 09:38:31 -0700 · parents c188f134af3e

Log and report error if it's not possible to play the track.
 public/index.html |  3 +--
 public/js/main.js | 10 ++++++++--
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/public/index.html b/public/index.html
index afaf530..c1a6c65 100644
--- a/public/index.html
+++ b/public/index.html
@@ -34,7 +34,6 @@
     <!-- INTRO -->
     <button type="button" class="collapsible">What is this?</button>
     <div id="intro" class="content active">
-
         <div>
             Specify a duration like "5:32", and <b>Hawk</b> will find all the songs in your Spotify library
             with that length, and with a single click you can start playing that song.
@@ -138,7 +137,7 @@
                 <span>(${duration})</span>
             </div>
             <div>
-                <button onclick="playChosenSong('${trackId}')">
+                <button onclick="playChosenSong('${name}', '${trackId}')">
                     <span class="icon-and-label">
                         <span class="material-symbols-outlined">
                             play_arrow
diff --git a/public/js/main.js b/public/js/main.js
index 5853114..ceb9209 100644
--- a/public/js/main.js
+++ b/public/js/main.js
@@ -167,8 +167,14 @@ async function pauseOrPlay() {
     setCurrentPlayingSong();
 }
 
-async function playChosenSong(trackId) {
-    await playTrack(trackId);
+async function playChosenSong(trackName, trackId) {
+    try {
+        await playTrack(trackId);
+    } catch (e) {
+        console.log("Error playing track")
+        console.log(e);
+        reportStatus(e);
+    }
     setCurrentPlayingSong();
 }