refactor: Use early returns instead of if-else
Signed-off-by: Tim Hårek Andreassen <tim@harek.no>
This commit is contained in:
parent
77428d374a
commit
a5db00c824
13
lib/nrk.ts
13
lib/nrk.ts
|
|
@ -48,9 +48,8 @@ export const nrkRadio = {
|
||||||
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
|
>(`https://psapi.nrk.no/radio/search/search?q=${query}`);
|
||||||
if (status === OK && response) {
|
if (status === OK && response) {
|
||||||
return response.results.series?.results;
|
return response.results.series?.results;
|
||||||
} else {
|
|
||||||
throw `Something went wrong with ${query} - got status ${status}`;
|
|
||||||
}
|
}
|
||||||
|
throw `Something went wrong with ${query} - got status ${status}`;
|
||||||
},
|
},
|
||||||
getSerieData: async (seriesId: string) => {
|
getSerieData: async (seriesId: string) => {
|
||||||
const [
|
const [
|
||||||
|
|
@ -76,17 +75,15 @@ export const nrkRadio = {
|
||||||
...serieResponse.series,
|
...serieResponse.series,
|
||||||
episodes,
|
episodes,
|
||||||
};
|
};
|
||||||
} else {
|
|
||||||
throw `Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`;
|
|
||||||
}
|
}
|
||||||
|
throw `Error getting episodes for ${seriesId}: EpisodeStatus: ${episodeStatus}. SerieStatus: ${seriesStatus}`;
|
||||||
},
|
},
|
||||||
getEpisode: async (seriesId: string, episodeId: string): Promise<OriginalEpisode | null> => {
|
getEpisode: async (seriesId: string, episodeId: string): Promise<OriginalEpisode | null> => {
|
||||||
const url = `https://psapi.nrk.no/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
|
const url = `https://psapi.nrk.no/radio/catalog/podcast/${seriesId}/episodes/${episodeId}`;
|
||||||
const [status, episode] = await get<OriginalEpisode>(url);
|
const [status, episode] = await get<OriginalEpisode>(url);
|
||||||
if (status !== OK) {
|
if (status === OK && episode) {
|
||||||
throw `Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return episode;
|
return episode;
|
||||||
|
}
|
||||||
|
throw `Error getting episode ${episodeId}. Status: ${status}. Series: ${seriesId}`;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue