Error handling Rename
This commit is contained in:
@@ -54,7 +54,7 @@ import {
|
|||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
import Link from "next/link";
|
import Link from "next/link";
|
||||||
import { ColumnDef } from "@tanstack/react-table";
|
import { ColumnDef } from "@tanstack/react-table";
|
||||||
import { Error } from "_components/Error";
|
import { Error as ErrorComponent } from "_components/Error";
|
||||||
import { useSession } from "next-auth/react";
|
import { useSession } from "next-auth/react";
|
||||||
import { setStandardName } from "../../../../../../helper/discord";
|
import { setStandardName } from "../../../../../../helper/discord";
|
||||||
import { penaltyColumns } from "(app)/admin/penalty/columns";
|
import { penaltyColumns } from "(app)/admin/penalty/columns";
|
||||||
@@ -73,7 +73,7 @@ export const ProfileForm: React.FC<ProfileFormProps> = ({ user }: ProfileFormPro
|
|||||||
defaultValues: user,
|
defaultValues: user,
|
||||||
resolver: zodResolver(UserOptionalDefaultsSchema),
|
resolver: zodResolver(UserOptionalDefaultsSchema),
|
||||||
});
|
});
|
||||||
if (!user) return <Error title="User not found" statusCode={404} />;
|
if (!user) return <ErrorComponent title="User not found" statusCode={404} />;
|
||||||
return (
|
return (
|
||||||
<form
|
<form
|
||||||
className="card-body"
|
className="card-body"
|
||||||
@@ -663,21 +663,25 @@ export const AdminForm = ({
|
|||||||
>
|
>
|
||||||
<Button
|
<Button
|
||||||
onClick={async () => {
|
onClick={async () => {
|
||||||
const res = (await setStandardName({
|
try {
|
||||||
memberId: discordAccount.discordId,
|
const response = await setStandardName({
|
||||||
userId: user.id,
|
memberId: discordAccount.discordId,
|
||||||
})) as unknown as { error?: string };
|
userId: user.id,
|
||||||
console.log(res);
|
});
|
||||||
if (res?.error) {
|
if (response?.error) {
|
||||||
toast.error(res.error);
|
throw new Error(response.error);
|
||||||
return;
|
}
|
||||||
|
toast.success("Standard Name wurde gesetzt!", {
|
||||||
|
style: {
|
||||||
|
background: "var(--color-base-100)",
|
||||||
|
color: "var(--color-base-content)",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
toast.error(
|
||||||
|
"Fehler beim setzen des Standard Namens: " + (error as Error).message,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
toast.success("Standard Name wurde gesetzt!", {
|
|
||||||
style: {
|
|
||||||
background: "var(--color-base-100)",
|
|
||||||
color: "var(--color-base-content)",
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
className="btn-sm btn-outline btn-info w-full"
|
className="btn-sm btn-outline btn-info w-full"
|
||||||
>
|
>
|
||||||
|
|||||||
@@ -55,17 +55,14 @@ export const setStandardName = async ({
|
|||||||
memberId: string;
|
memberId: string;
|
||||||
userId: string;
|
userId: string;
|
||||||
}) => {
|
}) => {
|
||||||
return discordAxiosClient
|
try {
|
||||||
.post("/helper/set-standard-name", {
|
await discordAxiosClient.post("/helper/set-standard-name", {
|
||||||
memberId,
|
memberId,
|
||||||
userId,
|
userId,
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
console.log("Error removing roles from member:", error);
|
|
||||||
return {
|
|
||||||
error:
|
|
||||||
((error as unknown as AxiosError).response?.data as unknown as { error: string }).error ||
|
|
||||||
(error as unknown as AxiosError).message,
|
|
||||||
};
|
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
return {
|
||||||
|
error: (error as AxiosError<{ error: string }>).response?.data.error || "Unknown error",
|
||||||
|
};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user