1
0
mirror of https://github.com/stonith404/pingvin-share.git synced 2024-09-30 16:40:11 +02: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();
let database = new sdk.Database(client);
let storage = new sdk.Storage(client);
client

View File

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

View File

@ -3,26 +3,28 @@ import { useModals } from "@mantine/modals";
import { ModalsContextProps } from "@mantine/modals/lib/context";
import { useRouter } from "next/router";
const showShareNotFoundModal = (modals: ModalsContextProps) => {
const showErrorModal = (
modals: ModalsContextProps,
title: string,
text: string
) => {
return modals.openModal({
closeOnClickOutside: false,
withCloseButton: 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 router = useRouter();
return (
<>
<Group grow direction="column">
<Text size="sm">
This share can't be found. Please check your link.
</Text>
<Text size="sm">{text}</Text>
<Button
onClick={() => {
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 FileList from "../../components/share/FileList";
import showEnterPasswordModal from "../../components/share/showEnterPasswordModal";
import showShareNotFoundModal from "../../components/share/showShareNotFoundModal";
import showVisitorLimitExceededModal from "../../components/share/showVisitorLimitExceededModal";
import showErrorModal from "../../components/share/showErrorModal";
import authService from "../../services/auth.service";
import shareService from "../../services/share.service";
import { AppwriteFileWithPreview } from "../../types/File.type";
@ -40,11 +39,27 @@ const Share = () => {
.catch((e) => {
const error = e.response.data.message;
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") {
showEnterPasswordModal(modals, submitPassword);
} 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.");
}
});
};