1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-11-05 15:30:14 +01:00

Improve share error handling

This commit is contained in:
Elias Schneider 2022-05-08 14:16:19 +02:00
parent 116c3403ff
commit 7c67c5b312
No known key found for this signature in database
GPG Key ID: D5EC1C72D93244FD
5 changed files with 30 additions and 53 deletions

View File

@ -4,7 +4,6 @@ module.exports = async function (req, res) {
const client = new sdk.Client(); const client = new sdk.Client();
let database = new sdk.Database(client); let database = new sdk.Database(client);
let storage = new sdk.Storage(client); let storage = new sdk.Storage(client);
client client

View File

@ -35,7 +35,7 @@ module.exports = async function (req, res) {
} }
let userIds; let userIds;
if (payload.emails) { if (payload.emails.length > 0) {
const creatorEmail = (await users.get(userId)).email const creatorEmail = (await users.get(userId)).email
userIds = [] userIds = []
userIds.push(userId) userIds.push(userId)

View File

@ -3,26 +3,28 @@ import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context"; import { ModalsContextProps } from "@mantine/modals/lib/context";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
const showShareNotFoundModal = (modals: ModalsContextProps) => { const showErrorModal = (
modals: ModalsContextProps,
title: string,
text: string
) => {
return modals.openModal({ return modals.openModal({
closeOnClickOutside: false, closeOnClickOutside: false,
withCloseButton: false, withCloseButton: false,
closeOnEscape: false, closeOnEscape: false,
title: <Title order={4}>Not found</Title>, title: <Title order={4}>{title}</Title>,
children: <Body />, children: <Body text={text} />,
}); });
}; };
const Body = () => { const Body = ({ text }: { text: string }) => {
const modals = useModals(); const modals = useModals();
const router = useRouter(); const router = useRouter();
return ( return (
<> <>
<Group grow direction="column"> <Group grow direction="column">
<Text size="sm"> <Text size="sm">{text}</Text>
This share can't be found. Please check your link.
</Text>
<Button <Button
onClick={() => { onClick={() => {
modals.closeAll(); modals.closeAll();
@ -36,4 +38,4 @@ const Body = () => {
); );
}; };
export default showShareNotFoundModal; export default showErrorModal;

View File

@ -1,39 +0,0 @@
import { Button, Group, Text, Title } from "@mantine/core";
import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context";
import { useRouter } from "next/router";
const showVisitorLimitExceededModal = (modals: ModalsContextProps) => {
return modals.openModal({
closeOnClickOutside: false,
withCloseButton: false,
closeOnEscape: false,
title: <Title order={4}>Visitor limit exceeded</Title>,
children: <Body />,
});
};
const Body = () => {
const modals = useModals();
const router = useRouter();
return (
<>
<Group grow direction="column">
<Text size="sm">
The visitor count limit from this share has been exceeded.
</Text>
<Button
onClick={() => {
modals.closeAll();
router.back();
}}
>
Go back
</Button>
</Group>
</>
);
};
export default showVisitorLimitExceededModal;

View File

@ -6,8 +6,7 @@ import Meta from "../../components/Meta";
import DownloadAllButton from "../../components/share/DownloadAllButton"; import DownloadAllButton from "../../components/share/DownloadAllButton";
import FileList from "../../components/share/FileList"; import FileList from "../../components/share/FileList";
import showEnterPasswordModal from "../../components/share/showEnterPasswordModal"; import showEnterPasswordModal from "../../components/share/showEnterPasswordModal";
import showShareNotFoundModal from "../../components/share/showShareNotFoundModal"; import showErrorModal from "../../components/share/showErrorModal";
import showVisitorLimitExceededModal from "../../components/share/showVisitorLimitExceededModal";
import authService from "../../services/auth.service"; import authService from "../../services/auth.service";
import shareService from "../../services/share.service"; import shareService from "../../services/share.service";
import { AppwriteFileWithPreview } from "../../types/File.type"; import { AppwriteFileWithPreview } from "../../types/File.type";
@ -40,11 +39,27 @@ const Share = () => {
.catch((e) => { .catch((e) => {
const error = e.response.data.message; const error = e.response.data.message;
if (e.response.status == 404) { if (e.response.status == 404) {
showShareNotFoundModal(modals); showErrorModal(
modals,
"Not found",
"This share can't be found. Please check your link."
);
} else if (error == "password_required") { } else if (error == "password_required") {
showEnterPasswordModal(modals, submitPassword); showEnterPasswordModal(modals, submitPassword);
} else if (error == "visitor_limit_exceeded") { } else if (error == "visitor_limit_exceeded") {
showVisitorLimitExceededModal(modals); showErrorModal(
modals,
"Visitor limit exceeded",
"The visitor limit from this share has been exceeded."
);
} else if (error == "forbidden") {
showErrorModal(
modals,
"Forbidden",
"You're not allowed to see this share. Are you logged in with the correct account?"
);
} else {
showErrorModal(modals, "Error", "An unknown error occurred.");
} }
}); });
}; };