mirror of
https://github.com/swissmakers/swiss-datashare.git
synced 2026-04-11 10:27:01 +02:00
fix: add error handling for uploading
This commit is contained in:
@@ -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);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user