forked from potsda.mn/mobilizon
fix(front): properly handle post not found
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
parent
1858580714
commit
8db31c99df
|
@ -1,5 +1,5 @@
|
||||||
<template>
|
<template>
|
||||||
<section class="container mx-auto pt-4 is-max-desktop max-w-2xl">
|
<section class="container mx-auto py-4 is-max-desktop max-w-2xl">
|
||||||
<div class="">
|
<div class="">
|
||||||
<div class="">
|
<div class="">
|
||||||
<picture>
|
<picture>
|
||||||
|
|
|
@ -282,6 +282,7 @@ import Link from "vue-material-design-icons/Link.vue";
|
||||||
import { Dialog } from "@/plugins/dialog";
|
import { Dialog } from "@/plugins/dialog";
|
||||||
import { useI18n } from "vue-i18n";
|
import { useI18n } from "vue-i18n";
|
||||||
import { Notifier } from "@/plugins/notifier";
|
import { Notifier } from "@/plugins/notifier";
|
||||||
|
import { AbsintheGraphQLErrors } from "@/types/errors.model";
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
slug: string;
|
slug: string;
|
||||||
|
@ -303,10 +304,27 @@ const { result: membershipsResult, loading: membershipsLoading } = useQuery<{
|
||||||
);
|
);
|
||||||
const memberships = computed(() => membershipsResult.value?.person.memberships);
|
const memberships = computed(() => membershipsResult.value?.person.memberships);
|
||||||
|
|
||||||
const { result: postResult, loading: postLoading } = useQuery<{
|
const {
|
||||||
|
result: postResult,
|
||||||
|
loading: postLoading,
|
||||||
|
onError: onFetchPostError,
|
||||||
|
} = useQuery<{
|
||||||
post: IPost;
|
post: IPost;
|
||||||
}>(FETCH_POST, () => ({ slug: props.slug }));
|
}>(FETCH_POST, () => ({ slug: props.slug }));
|
||||||
|
|
||||||
|
const handleErrors = (errors: AbsintheGraphQLErrors): void => {
|
||||||
|
if (
|
||||||
|
errors.some((error) => error.status_code === 404) ||
|
||||||
|
errors.some(({ message }) => message.includes("has invalid value $uuid"))
|
||||||
|
) {
|
||||||
|
router.replace({ name: RouteName.PAGE_NOT_FOUND });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
onFetchPostError(({ graphQLErrors }) =>
|
||||||
|
handleErrors(graphQLErrors as AbsintheGraphQLErrors)
|
||||||
|
);
|
||||||
|
|
||||||
const post = computed(() => postResult.value?.post);
|
const post = computed(() => postResult.value?.post);
|
||||||
|
|
||||||
usePersonStatusGroup(usernameWithDomain(post.value?.attributedTo as IGroup));
|
usePersonStatusGroup(usernameWithDomain(post.value?.attributedTo as IGroup));
|
||||||
|
|
Loading…
Reference in a new issue