Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: handle fetch error
Browse files Browse the repository at this point in the history
cstaelen committed Jan 19, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 4789801 commit b371a1e
Showing 9 changed files with 21 additions and 30 deletions.
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -3,11 +3,15 @@ Tidarr notable changes.

[Keep a Changelog](http://keepachangelog.com/en/1.0.0/) format.

## 📦 0.1.14
### 🐛 Fixed
* [Front] Show "No results" message instead of loader when tidal fetch fail

## 📦 0.1.13
### 🖍 Changed
* [API] Gotify notification title shows content type instead of "album"
### 🐛 Fixed
* [API] Fix missing `ffmpeg-python` pip package (#57)
* [Chore] Fix missing `ffmpeg-python` pip package (#57)

## 📦 0.1.12
### 🚀 Added
2 changes: 1 addition & 1 deletion api/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidarr-api",
"version": "0.1.13",
"version": "0.1.14",
"private": true,
"devDependencies": {
"@eslint/js": "^9.15.0",
4 changes: 2 additions & 2 deletions app/src/hooks/useAlbum.tsx
Original file line number Diff line number Diff line change
@@ -25,9 +25,9 @@ export const useAlbum = (id: string | undefined): AlbumContextType => {
TidalModuleResponseType<{ item: TrackType }>
>(`${TIDAL_API_LISTEN_URL}/pages/album?albumId=${id}`);

setAlbum(data_album.rows[0].modules[0].album);
setAlbum(data_album?.rows[0].modules[0].album);

const data_tracks = data_album.rows[1].modules[0].pagedList.items.map(
const data_tracks = data_album?.rows[1].modules[0].pagedList.items.map(
(track) => track.item,
);

12 changes: 7 additions & 5 deletions app/src/hooks/usePlaylist.tsx
Original file line number Diff line number Diff line change
@@ -40,11 +40,13 @@ export const usePlaylist = (id: string | undefined): PlaylistContextType => {
}`,
);

setTracks([
...(tracks || ([] as TrackType[])),
...data_tracks.items.map((playlist) => playlist.item),
]);
setTotal(data_tracks.totalNumberOfItems);
if (data_tracks) {
setTracks([
...(tracks || ([] as TrackType[])),
...data_tracks.items.map((playlist) => playlist.item),
]);
setTotal(data_tracks.totalNumberOfItems);
}
setLoading(false);
}

5 changes: 2 additions & 3 deletions app/src/provider/ArtistProvider.tsx
Original file line number Diff line number Diff line change
@@ -33,7 +33,6 @@ const ArtistContext = React.createContext<ArtistContextType>(

export function ArtistProvider({ children }: { children: ReactNode }) {
const [loading, setLoading] = useState<boolean>(false);

const [artistPagerLoading, setArtistPagerLoading] = useState<number>();
const [artistResults, setArtistResults] = useState<ArtistResultsType>(
{} as ArtistResultsType,
@@ -46,7 +45,7 @@ export function ArtistProvider({ children }: { children: ReactNode }) {
`${TIDAL_API_LISTEN_URL}/pages/artist?artistId=${id}`,
);

if (data_artist?.rows?.length > 0) {
if (data_artist && data_artist?.rows?.length > 0) {
const album_block = data_artist?.rows
.filter(
(row) =>
@@ -79,7 +78,7 @@ export function ArtistProvider({ children }: { children: ReactNode }) {
}`,
);

if (data_artist_page?.items?.length > 0) {
if (data_artist_page && data_artist_page?.items?.length > 0) {
const clone: TidalModuleListType<AlbumType>[] = [
...(artistResults?.blocks || []),
];
2 changes: 1 addition & 1 deletion app/src/provider/SearchProvider.tsx
Original file line number Diff line number Diff line change
@@ -100,7 +100,7 @@ export function SearchProvider({ children }: { children: ReactNode }) {
},
};

setSearchResults(data);
setSearchResults(data as TidalResponseType);
}

async function directDownload(url: string) {
16 changes: 1 addition & 15 deletions app/src/utils/fetch.ts
Original file line number Diff line number Diff line change
@@ -3,7 +3,7 @@ const jsonMimeType = "application/json";
export async function fetchTidal<T>(
url: string,
options: RequestInit = {},
): Promise<T> {
): Promise<T | undefined> {
const TOKEN = window._env_.REACT_APP_TIDAL_SEARCH_TOKEN;
const COUNTRY = window._env_.REACT_APP_TIDAL_COUNTRY_CODE;

@@ -28,18 +28,4 @@ export async function fetchTidal<T>(
if (response?.ok) {
return await response.json();
}

// error

if (500 <= response?.status) {
throw new Error("An error occured");
}
if (403 === response?.status) {
throw new Error("Authorization error");
}
if (404 === response?.status) {
throw new Error("Not found");
}

throw new Error();
}
2 changes: 1 addition & 1 deletion e2e/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidarr-testing",
"version": "0.1.13",
"version": "0.1.14",
"description": "",
"main": "index.js",
"keywords": [],
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "tidarr-main",
"version": "0.1.13",
"version": "0.1.14",
"private": true,
"devDependencies": {
"concurrently": "^8.2.2"

0 comments on commit b371a1e

Please sign in to comment.