Skip to content

Commit

Permalink
Fix: add response data verification with alternative list when data i…
Browse files Browse the repository at this point in the history
…s not present (see #40)
  • Loading branch information
mateussouzaweb committed Feb 10, 2024
1 parent 3a7eafe commit ac2b596
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 10 deletions.
3 changes: 2 additions & 1 deletion src/scripts/history.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ const listHistory: Callback = async ({ state, render }) => {
'page_size': limit.toString()
})

const items = response.data.filter((item) => {
const data = response.data || []
const items = data.filter((item) => {
return item.panel.type === 'episode'
}).map((item) => {
return {
Expand Down
15 changes: 10 additions & 5 deletions src/scripts/home.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ const listResults: Callback = async ({ state, render }) => {
// ]

// const listsResponse = await App.homeFeed({})
// const lists = listsResponse.data.filter((list: any) => {
// const listsData = listsResponse.data || []
// const lists = listsData.filter((list: any) => {
// return validLists.includes(list.response_type)
// })

const recommendationsResponse = await App.recommendations({'n': '4'})
const recommendations = (recommendationsResponse.data || []).map((item) => {
const recommendationsData = recommendationsResponse.data || []
const recommendations = recommendationsData.map((item) => {
return {
id: item.id,
name: item.title,
Expand All @@ -61,7 +63,8 @@ const listResults: Callback = async ({ state, render }) => {
})

const historyResponse = await App.history({'page_size': '4'})
const history = (historyResponse.data || []).filter((item) => {
const historyData = historyResponse.data || []
const history = historyData.filter((item) => {
return item.panel.type === 'episode'
}).map((item) => {
return {
Expand All @@ -81,7 +84,8 @@ const listResults: Callback = async ({ state, render }) => {
})

const watchlistResponse = await App.watchlist({'n': '4'})
const watchlist = (watchlistResponse.data || []).map((item) => {
const watchlistData = watchlistResponse.data || []
const watchlist = watchlistData.map((item) => {
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
Expand All @@ -99,7 +103,8 @@ const listResults: Callback = async ({ state, render }) => {
})

const popularResponse = await App.browser({'n': '4', 'sort_by': 'popularity'})
const popular = (popularResponse.data || []).map((item) => {
const popularData = popularResponse.data || []
const popular = popularData.map((item) => {
return {
id: item.id,
name: item.title,
Expand Down
4 changes: 2 additions & 2 deletions src/scripts/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ const listResults: Callback = async ({ state, render }) => {
}

if( response.data && response.data.length ){
data.count = response.data[0].count
data.items = response.data[0].items
data.count = response.data[0].count || 0
data.items = response.data[0].items || []
}

const total = data.count
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/serie.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,8 @@ const listSerieInfo: Callback = async ({ state }) => {
state.inWatchlist = inWatchlist

const seasonsResponse = await App.seasons(serieId, {})
const seasons = seasonsResponse.items.map((item) => {
const seasonItems = seasonsResponse.items || []
const seasons = seasonItems.map((item) => {
return {
id: item.id,
name: 'S' + item.season_number + ': ' + item.title
Expand Down
3 changes: 2 additions & 1 deletion src/scripts/watchlist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ const listWatchlist: Callback = async ({ state, render }) => {
'n': limit.toString(),
})

const items = response.data.map((item) => {
const data = response.data || []
const items = data.map((item) => {
return {
id: item.panel.id,
image: App.getImage(item.panel.images.thumbnail).source,
Expand Down

0 comments on commit ac2b596

Please sign in to comment.