🔧 fix(Shared Links): Handling Shared Link Errors (#3118)

* refactor: add error handling in Share model

* refactor: add error handing to API routers

* refactor: display error message when API response is an error

* chore: remove unneccesary JSON.stringify

* chore: revert unintended changes

---------

Co-authored-by: Danny Avila <danny@librechat.ai>
This commit is contained in:
Yuichi Oneda 2024-06-21 07:12:37 -07:00 committed by GitHub
parent 3172381bad
commit 4e4de88faa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 323 additions and 75 deletions

View file

@ -1,8 +1,10 @@
import { useState } from 'react';
import copy from 'copy-to-clipboard';
import { Copy, Link } from 'lucide-react';
import { useUpdateSharedLinkMutation } from '~/data-provider';
import type { TSharedLink } from 'librechat-data-provider';
import { useUpdateSharedLinkMutation } from '~/data-provider';
import { NotificationSeverity } from '~/common';
import { useToastContext } from '~/Providers';
import { Spinner } from '~/components/svg';
import { Button } from '~/components/ui';
import { useLocalize } from '~/hooks';
@ -21,8 +23,18 @@ export default function SharedLinkButton({
setIsUpdated: (isUpdated: boolean) => void;
}) {
const localize = useLocalize();
const { showToast } = useToastContext();
const [isCopying, setIsCopying] = useState(false);
const { mutateAsync, isLoading } = useUpdateSharedLinkMutation();
const { mutateAsync, isLoading } = useUpdateSharedLinkMutation({
onError: () => {
showToast({
message: localize('com_ui_share_error'),
severity: NotificationSeverity.ERROR,
showIcon: true,
});
},
});
const copyLink = () => {
if (!share) {