Gracefully handle missing playlists in Playlet backend (#670)

* Gracefully handle missing playlists in Playlet backend

* Changelog
This commit is contained in:
Brahim Hadriche authored and GitHub committed 2025-06-26 22:02:51 -04:00
1 parent 45a85f92b3
commit 19f304bd3e
2 files changed
+80 -77

No files matched your search

+3 -1
View File
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased] ## [Unreleased]
- Nothing worth mentioning yet. ### Fixed
- A bug preventing the removal of bookmarked private playlists
## [0.40.8] - 2025-06-22 ## [0.40.8] - 2025-06-22
@@ -417,23 +417,27 @@ namespace Invidious
function DefaultHandler(context as object) as object function DefaultHandler(context as object) as object
response = context.response response = context.response
if response.StatusCode() = 200 if not response.IsSuccess()
json = response.Json() return invalid
if IsArray(json)
json = {
items: json
}
end if
return json
end if end if
return invalid
json = response.Json()
if json = invalid
return invalid
end if
if IsArray(json)
json = {
items: json
}
end if
return json
end function end function
function PlaylistHandler(context as object) as object function PlaylistHandler(context as object) as object
response = context.response response = context.response
statusCode = response.StatusCode() if not response.IsSuccess()
if statusCode = 404
' Similar to VideoInfoHandler, we can return a valid response ' Similar to VideoInfoHandler, we can return a valid response
' in case of a deleted playlist. ' in case of a deleted playlist.
response.OverrideStatusCode(200) response.OverrideStatusCode(200)
@@ -447,24 +451,24 @@ namespace Invidious
} }
end if end if
if statusCode = 200 json = response.Json()
json = response.Json() if json = invalid
result = { return invalid
items: json.videos
}
if json.continuation <> invalid
result.continuation = json.continuation
end if
return result
end if end if
return invalid
result = {
items: json.videos
}
if json.continuation <> invalid
result.continuation = json.continuation
end if
return result
end function end function
function ChannelVideosHandler(context as object) as object function ChannelVideosHandler(context as object) as object
response = context.response response = context.response
statusCode = response.StatusCode() if not response.IsSuccess()
if statusCode = 404 or statusCode = 500
' Similar to VideoInfoHandler, we can return a valid response ' Similar to VideoInfoHandler, we can return a valid response
' in case of a deleted channel. ' in case of a deleted channel.
response.OverrideStatusCode(200) response.OverrideStatusCode(200)
@@ -478,46 +482,43 @@ namespace Invidious
} }
end if end if
if response.StatusCode() = 200 json = response.Json()
json = response.Json() if json = invalid
return { return invalid
items: json.videos
continuation: json.continuation
sortOptions: json.sortOptions
}
end if end if
return invalid
return {
items: json.videos
continuation: json.continuation
sortOptions: json.sortOptions
}
end function end function
function ChannelPlaylistsHandler(context as object) as object function ChannelPlaylistsHandler(context as object) as object
response = context.response response = context.response
if response.StatusCode() = 200 if not response.IsSuccess()
json = response.Json() return invalid
' Courses are not yet implemented in Invidious. end if
' In this case, Invidious returns 200, but the response is empty.
' https://github.com/iv-org/invidious/issues/5088
' https://github.com/iv-org/invidious/issues/5144
if json = invalid
json = {
playlists: []
}
end if
return { json = response.Json()
items: json.playlists if json = invalid
continuation: json.continuation json = {
sortOptions: json.sortOptions playlists: []
} }
end if end if
return invalid
return {
items: json.playlists
continuation: json.continuation
sortOptions: json.sortOptions
}
end function end function
function VideoInfoHandler(context as object) as object function VideoInfoHandler(context as object) as object
response = context.response response = context.response
statusCode = response.StatusCode() if not response.IsSuccess()
if statusCode >= 500 or statusCode = 404
' In some cases, such as a video became private, or a live stream ended, ' In some cases, such as a video became private, or a live stream ended,
' Invidious returns a 500 error. We can in this case return a valid response ' Invidious returns a 500 error. We can in this case return a valid response
' with just a video id, which will allow us to show a valid thumbnail if possible. ' with just a video id, which will allow us to show a valid thumbnail if possible.
@@ -533,22 +534,21 @@ namespace Invidious
} }
end if end if
if statusCode = 200 json = response.Json()
json = response.Json() if json = invalid
json.type = "video" return invalid
return {
items: [json]
}
end if end if
return invalid json.type = "video"
return {
items: [json]
}
end function end function
function PlaylistInfoHandler(context as object) as object function PlaylistInfoHandler(context as object) as object
response = context.response response = context.response
statusCode = response.StatusCode() if not response.IsSuccess()
if statusCode = 404
' Similar to VideoInfoHandler, we can return a valid response ' Similar to VideoInfoHandler, we can return a valid response
' in case of a deleted playlist. ' in case of a deleted playlist.
response.OverrideStatusCode(200) response.OverrideStatusCode(200)
@@ -561,21 +561,21 @@ namespace Invidious
} }
end if end if
if statusCode = 200 json = response.Json()
json = response.Json() if json = invalid
json.type = "playlist" return invalid
return {
items: [json]
}
end if end if
return invalid
json.type = "playlist"
return {
items: [json]
}
end function end function
function ChannelInfoHandler(context as object) as object function ChannelInfoHandler(context as object) as object
response = context.response response = context.response
statusCode = response.StatusCode() if not response.IsSuccess()
if statusCode = 404 or statusCode = 500
' Similar to VideoInfoHandler, we can return a valid response ' Similar to VideoInfoHandler, we can return a valid response
' in case of a deleted channel. ' in case of a deleted channel.
response.OverrideStatusCode(200) response.OverrideStatusCode(200)
@@ -588,14 +588,15 @@ namespace Invidious
} }
end if end if
if statusCode = 200 json = response.Json()
json = response.Json() if json = invalid
json.type = "channel" return invalid
return {
items: [json]
}
end if end if
return invalid
json.type = "channel"
return {
items: [json]
}
end function end function
function AuthFeedHandler(context as object) as object function AuthFeedHandler(context as object) as object
@@ -604,7 +605,7 @@ namespace Invidious
m.DeleteExpiredToken(response, authToken) m.DeleteExpiredToken(response, authToken)
if response.StatusCode() <> 200 if not response.IsSuccess()
return invalid return invalid
end if end if
@@ -640,7 +641,7 @@ namespace Invidious
m.DeleteExpiredToken(response, authToken) m.DeleteExpiredToken(response, authToken)
if response.StatusCode() <> 200 if not response.IsSuccess()
return invalid return invalid
end if end if