rollback if an error occurs while setting share state

This commit is contained in:
MarconLP 2023-04-14 15:34:14 +02:00
parent dd8c96c7ad
commit 62555101b2
No known key found for this signature in database
GPG key ID: A08A9C8B623F5EA5
2 changed files with 10 additions and 0 deletions

View file

@ -20,6 +20,12 @@ export function ShareModal({ video }: Props) {
}
return { previousValue };
},
onError: async (err, { videoId }, context) => {
if (context?.previousValue) {
utils.video.get.setData({ videoId }, context.previousValue);
}
console.error(err.message);
},
});
const [linkCopied, setLinkCopied] = useState<boolean>(false);

View file

@ -91,6 +91,10 @@ export const videoRouter = createTRPCRouter({
},
});
if (updateVideo.count === 0) {
throw new TRPCError({ code: "FORBIDDEN" });
}
return {
success: true,
updateVideo,