Handle 400 error code when accesing a non public collection
This commit is contained in:
parent
2264abd384
commit
1b9dafbe47
|
@ -9,6 +9,8 @@ const getPublicCollectionData = async (
|
||||||
) => {
|
) => {
|
||||||
const res = await fetch("/api/v1/public/collections/" + collectionId);
|
const res = await fetch("/api/v1/public/collections/" + collectionId);
|
||||||
|
|
||||||
|
if (res.status === 400) return { response: "Collection not found.", status: 400 };
|
||||||
|
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
|
|
||||||
setData(data.response);
|
setData(data.response);
|
||||||
|
|
|
@ -68,12 +68,15 @@ export default function PublicCollections() {
|
||||||
searchByTags: searchFilter.tags,
|
searchByTags: searchFilter.tags,
|
||||||
});
|
});
|
||||||
|
|
||||||
const [collection, setCollection] =
|
const [collection, setCollection] = useState<CollectionIncludingMembersAndLinkCount>();
|
||||||
useState<CollectionIncludingMembersAndLinkCount>();
|
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (router.query.id) {
|
if (router.query.id) {
|
||||||
getPublicCollectionData(Number(router.query.id), setCollection);
|
getPublicCollectionData(Number(router.query.id), setCollection).then((res) => {
|
||||||
|
if (res.status === 400) {
|
||||||
|
router.push("/dashboard");
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}, [collections]);
|
}, [collections]);
|
||||||
|
|
||||||
|
@ -108,8 +111,7 @@ export default function PublicCollections() {
|
||||||
<div
|
<div
|
||||||
className="h-96"
|
className="h-96"
|
||||||
style={{
|
style={{
|
||||||
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${
|
backgroundImage: `linear-gradient(${collection?.color}30 10%, ${settings.theme === "dark" ? "#262626" : "#f3f4f6"
|
||||||
settings.theme === "dark" ? "#262626" : "#f3f4f6"
|
|
||||||
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
|
} 13rem, ${settings.theme === "dark" ? "#171717" : "#ffffff"} 100%)`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
|
|
Ŝarĝante…
Reference in New Issue