rollback if an error occurs while setting share state
This commit is contained in:
parent
dd8c96c7ad
commit
62555101b2
2 changed files with 10 additions and 0 deletions
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -91,6 +91,10 @@ export const videoRouter = createTRPCRouter({
|
|||
},
|
||||
});
|
||||
|
||||
if (updateVideo.count === 0) {
|
||||
throw new TRPCError({ code: "FORBIDDEN" });
|
||||
}
|
||||
|
||||
return {
|
||||
success: true,
|
||||
updateVideo,
|
||||
|
|
|
|||
Loading…
Reference in a new issue