0
Fork 0
mirror of https://github.com/stonith404/pingvin-share.git synced 2025-02-19 01:55:48 -05:00

fix: add error handling for uploading

This commit is contained in:
Elias Schneider 2022-10-11 15:14:29 +02:00
parent ffd538f140
commit e2b3e6a1e8

View file

@ -1,5 +1,6 @@
import { Button, Group } from "@mantine/core"; import { Button, Group } from "@mantine/core";
import { useModals } from "@mantine/modals"; import { useModals } from "@mantine/modals";
import axios from "axios";
import { useRouter } from "next/router"; import { useRouter } from "next/router";
import { useState } from "react"; import { useState } from "react";
import Meta from "../components/Meta"; import Meta from "../components/Meta";
@ -11,6 +12,7 @@ import useUser from "../hooks/user.hook";
import shareService from "../services/share.service"; import shareService from "../services/share.service";
import { FileUpload } from "../types/File.type"; import { FileUpload } from "../types/File.type";
import { ShareSecurity } from "../types/share.type"; import { ShareSecurity } from "../types/share.type";
import toast from "../utils/toast.util";
const Upload = () => { const Upload = () => {
const router = useRouter(); const router = useRouter();
@ -49,10 +51,15 @@ const Upload = () => {
setFiles([]); setFiles([]);
} }
} }
} catch { } catch (e) {
files.forEach((file) => { files.forEach((file) => {
file.uploadingState = undefined; file.uploadingState = undefined;
}); });
if (axios.isAxiosError(e)) {
toast.error(e.response?.data?.message ?? "An unkown error occured.");
} else {
toast.error("An unkown error occured.");
}
setFiles([...files]); setFiles([...files]);
setisUploading(false); setisUploading(false);
} }