From 48ee0bba859b457b88a995ae97ae1d5c570c74e8 Mon Sep 17 00:00:00 2001 From: Kavin <20838718+FireMasterK@users.noreply.github.com> Date: Mon, 2 Jan 2023 20:59:57 +0000 Subject: [PATCH] Clean code and throw error if no video was added. --- .../handlers/auth/AuthPlaylistHandlers.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java b/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java index dafcacb..253598d 100644 --- a/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java +++ b/src/main/java/me/kavin/piped/server/handlers/auth/AuthPlaylistHandlers.java @@ -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();