Skip to content

Commit e1bf3ba

Browse files
committed
catch spotify errors in ui.
1 parent a12ca61 commit e1bf3ba

2 files changed

Lines changed: 22 additions & 7 deletions

File tree

src/pages/discover/index.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { useState } from "react";
22
import { invoke } from "@tauri-apps/api/core";
3+
import { message } from "@tauri-apps/plugin-dialog";
34
import { Music2 } from "lucide-react";
45
import { use_settings } from "@/ctx";
56
import { SpPlaylistList, SpTrackList } from "@/components/spotify/discover";
@@ -90,8 +91,9 @@ export function Discover() {
9091
const token = await sp_token();
9192
const pls = await invoke<SpPlaylist[]>("sp_playlists", { accessToken: token });
9293
set_sp_playlists(pls);
93-
} catch {
94+
} catch (e) {
9495
set_sp_playlists([]);
96+
message(`Failed to load playlists:\n${e}`, { title: "Spotify Error", kind: "error" });
9597
} finally {
9698
set_sp_loading(false);
9799
}
@@ -104,8 +106,9 @@ export function Discover() {
104106
const token = await sp_token();
105107
const tracks = await invoke<SpTrack[]>("sp_playlist_tracks", { accessToken: token, id: pl.id });
106108
set_sp_drill({ kind: "playlist", name: pl.name, tracks });
107-
} catch {
109+
} catch (e) {
108110
set_sp_drill({ kind: "playlist", name: pl.name, tracks: [] });
111+
message(`Failed to load playlist "${pl.name}":\n${e}`, { title: "Spotify Error", kind: "error" });
109112
}
110113
}
111114

@@ -116,8 +119,9 @@ export function Discover() {
116119
const token = await sp_token();
117120
const tracks = await invoke<SpTrack[]>("sp_liked_tracks", { accessToken: token });
118121
set_sp_drill({ kind: "liked", name: "Liked Songs", tracks });
119-
} catch {
122+
} catch (e) {
120123
set_sp_drill({ kind: "liked", name: "Liked Songs", tracks: [] });
124+
message(`Failed to load liked songs:\n${e}`, { title: "Spotify Error", kind: "error" });
121125
}
122126
}
123127

src/pages/discover/onboarding/step_migrate/index.tsx

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { useState, useEffect, useRef } from "react";
22
import { invoke } from "@tauri-apps/api/core";
33
import { listen } from "@tauri-apps/api/event";
4+
import { message } from "@tauri-apps/plugin-dialog";
45
import { use_lib, use_settings } from "@/ctx";
56
import type { SpPlaylist, SpTrack } from "@/components/spotify/discover";
67
import type { YtPlaylistResult, YtTrack } from "@/components/youtube/discover";
@@ -194,8 +195,9 @@ export function StepMigrate({ on_next }: Props) {
194195
});
195196
set_sp_pls(pls);
196197
set_sp_checked(new Set(pls.map((p) => p.id)));
197-
} catch {
198+
} catch (e) {
198199
set_sp_pls([]);
200+
message(`Failed to load playlists:\n${e}`, { title: "Spotify Error", kind: "error" });
199201
} finally {
200202
set_sp_pls_loading(false);
201203
}
@@ -216,7 +218,10 @@ export function StepMigrate({ on_next }: Props) {
216218
let token: string;
217219
try {
218220
token = await sp_token();
219-
} catch { return; }
221+
} catch (e) {
222+
message(`Failed to get Spotify token:\n${e}`, { title: "Spotify Error", kind: "error" });
223+
return;
224+
}
220225

221226
const items: {
222227
name: string;
@@ -230,7 +235,10 @@ export function StepMigrate({ on_next }: Props) {
230235
accessToken: token,
231236
});
232237
items.push({ name: "Liked Songs", kind: "liked", tracks });
233-
} catch (e) { console.error("sp_liked_tracks:", e); }
238+
} catch (e) {
239+
console.error("sp_liked_tracks:", e);
240+
message(`Failed to load liked songs:\n${e}`, { title: "Spotify Error", kind: "error" });
241+
}
234242
}
235243

236244
for (const id of sp_checked) {
@@ -242,7 +250,10 @@ export function StepMigrate({ on_next }: Props) {
242250
id,
243251
});
244252
items.push({ name: pl.name, kind: "playlist", tracks });
245-
} catch (e) { console.error("sp_playlist_tracks:", e); }
253+
} catch (e) {
254+
console.error("sp_playlist_tracks:", e);
255+
message(`Failed to load playlist "${pl.name}":\n${e}`, { title: "Spotify Error", kind: "error" });
256+
}
246257
}
247258

248259
const total = items.reduce((s, i) => s + i.tracks.length, 0);

0 commit comments

Comments
 (0)