Error handling Rename

This commit is contained in:
PxlLoewe
2026-02-01 00:18:26 +01:00
parent a60cd67c44
commit 4ae2e93249
2 changed files with 27 additions and 26 deletions

View File

@@ -54,7 +54,7 @@ import {
} from "lucide-react";
import Link from "next/link";
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 { setStandardName } from "../../../../../../helper/discord";
import { penaltyColumns } from "(app)/admin/penalty/columns";
@@ -73,7 +73,7 @@ export const ProfileForm: React.FC<ProfileFormProps> = ({ user }: ProfileFormPro
defaultValues: user,
resolver: zodResolver(UserOptionalDefaultsSchema),
});
if (!user) return <Error title="User not found" statusCode={404} />;
if (!user) return <ErrorComponent title="User not found" statusCode={404} />;
return (
<form
className="card-body"
@@ -663,14 +663,13 @@ export const AdminForm = ({
>
<Button
onClick={async () => {
const res = (await setStandardName({
try {
const response = await setStandardName({
memberId: discordAccount.discordId,
userId: user.id,
})) as unknown as { error?: string };
console.log(res);
if (res?.error) {
toast.error(res.error);
return;
});
if (response?.error) {
throw new Error(response.error);
}
toast.success("Standard Name wurde gesetzt!", {
style: {
@@ -678,6 +677,11 @@ export const AdminForm = ({
color: "var(--color-base-content)",
},
});
} catch (error) {
toast.error(
"Fehler beim setzen des Standard Namens: " + (error as Error).message,
);
}
}}
className="btn-sm btn-outline btn-info w-full"
>

View File

@@ -55,17 +55,14 @@ export const setStandardName = async ({
memberId: string;
userId: string;
}) => {
return discordAxiosClient
.post("/helper/set-standard-name", {
try {
await discordAxiosClient.post("/helper/set-standard-name", {
memberId,
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",
};
}
};