Error handling Rename
This commit is contained in:
@@ -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,21 +663,25 @@ export const AdminForm = ({
|
||||
>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
const res = (await setStandardName({
|
||||
memberId: discordAccount.discordId,
|
||||
userId: user.id,
|
||||
})) as unknown as { error?: string };
|
||||
console.log(res);
|
||||
if (res?.error) {
|
||||
toast.error(res.error);
|
||||
return;
|
||||
try {
|
||||
const response = await setStandardName({
|
||||
memberId: discordAccount.discordId,
|
||||
userId: user.id,
|
||||
});
|
||||
if (response?.error) {
|
||||
throw new Error(response.error);
|
||||
}
|
||||
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"
|
||||
>
|
||||
|
||||
@@ -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",
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user