Clean code and throw error if no video was added.

This commit is contained in:
Kavin 2023-01-02 20:59:57 +00:00
parent e5556f38e5
commit 48ee0bba85
No known key found for this signature in database
GPG Key ID: 49451E4482CC5BCD
1 changed files with 12 additions and 5 deletions

View File

@ -232,6 +232,8 @@ public class AuthPlaylistHandlers {
var videos = playlist.getVideos();
boolean added = false;
for (String videoId : videoIds) {
if (StringUtils.isEmpty(videoId)) continue;
@ -255,19 +257,24 @@ public class AuthPlaylistHandlers {
s.persist(video);
} catch (Exception e) {
// only return an error if the unavailable video is the only one in the request
if (videoIds.size() == 1) {
return mapper.writeValueAsBytes(mapper.createObjectNode()
.put("error", "The video is either private or got deleted"));
}
ExceptionHandler.handle(e);
continue;
}
}
if (playlist.getVideos().isEmpty()) playlist.setThumbnail(video.getThumbnail());
added = true;
videos.add(video);
}
if (!added) {
// only return an error if no videos were added
return mapper.writeValueAsBytes(mapper.createObjectNode()
.put("error", "Unable to add any videos, since they were unable to be fetched"));
}
var tr = s.beginTransaction();
s.merge(playlist);
tr.commit();