diff --git a/src/modules/music-kit.ts b/src/modules/music-kit.ts index 755e065..1d15d03 100644 --- a/src/modules/music-kit.ts +++ b/src/modules/music-kit.ts @@ -1,7 +1,6 @@ import { NativeModules } from 'react-native'; -import type { CatalogSearchType } from '../types/catalog-search-type'; +import type { CatalogSearchType, ICatalogSearch } from '../types/catalog-search'; import type { MusicItem } from '../types/music-item'; -import type { ISong } from '../types/song'; import type { ITracksFromLibrary } from '../types/tracks-from-library'; const { MusicModule } = NativeModules; @@ -23,14 +22,17 @@ class MusicKit { search: string, types: CatalogSearchType[], options?: IEndlessListOptions, - ): Promise { - const response: { results: ISong[] } = await MusicModule.catalogSearch(search, types, options); + ): Promise { + try { + return (await MusicModule.catalogSearch(search, types, options)) as ICatalogSearch; + } catch (error) { + console.error('Apple Music Kit: Catalog Search failed.', error); - if (response.results) { - return response.results; + return { + songs: [], + albums: [], + }; } - - return []; } /** diff --git a/src/types/album.ts b/src/types/album.ts new file mode 100644 index 0000000..f307214 --- /dev/null +++ b/src/types/album.ts @@ -0,0 +1,7 @@ +export interface IAlbum { + id: string; + title: string; + artistName: string; + artworkUrl: string; + trackCount: number; +} diff --git a/src/types/catalog-search-type.ts b/src/types/catalog-search-type.ts deleted file mode 100644 index 96b0a56..0000000 --- a/src/types/catalog-search-type.ts +++ /dev/null @@ -1,4 +0,0 @@ -export enum CatalogSearchType { - SONGS = 'songs', - ALBUMS = 'albums', -} diff --git a/src/types/catalog-search.ts b/src/types/catalog-search.ts new file mode 100644 index 0000000..5e51cae --- /dev/null +++ b/src/types/catalog-search.ts @@ -0,0 +1,12 @@ +import type { IAlbum } from './album'; +import type { ISong } from './song'; + +export enum CatalogSearchType { + SONGS = 'songs', + ALBUMS = 'albums', +} + +export interface ICatalogSearch { + songs: ISong[]; + albums: IAlbum[]; +}