Catch Blocks
This commit is contained in:
@@ -663,10 +663,15 @@ export const AdminForm = ({
|
||||
>
|
||||
<Button
|
||||
onClick={async () => {
|
||||
await setStandardName({
|
||||
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;
|
||||
}
|
||||
toast.success("Standard Name wurde gesetzt!", {
|
||||
style: {
|
||||
background: "var(--color-base-100)",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
"use server";
|
||||
import axios from "axios";
|
||||
import axios, { AxiosError } from "axios";
|
||||
|
||||
const discordAxiosClient = axios.create({
|
||||
baseURL: process.env.CORE_SERVER_URL || "http://localhost:3005",
|
||||
@@ -55,12 +55,17 @@ export const setStandardName = async ({
|
||||
memberId: string;
|
||||
userId: string;
|
||||
}) => {
|
||||
discordAxiosClient
|
||||
return discordAxiosClient
|
||||
.post("/helper/set-standard-name", {
|
||||
memberId,
|
||||
userId,
|
||||
})
|
||||
.catch((error) => {
|
||||
console.error("Error removing roles from member:", 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,
|
||||
};
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user