mirror of
https://github.com/Dokploy/dokploy
synced 2025-06-26 18:27:59 +00:00
refactor: improve error
This commit is contained in:
@@ -16,6 +16,7 @@ import { useEffect, useState } from "react";
|
|||||||
import ReactMarkdown from "react-markdown";
|
import ReactMarkdown from "react-markdown";
|
||||||
import { toast } from "sonner";
|
import { toast } from "sonner";
|
||||||
import type { TemplateInfo } from "./template-generator";
|
import type { TemplateInfo } from "./template-generator";
|
||||||
|
import { AlertBlock } from "@/components/shared/alert-block";
|
||||||
|
|
||||||
export interface StepProps {
|
export interface StepProps {
|
||||||
nextStep: () => void;
|
nextStep: () => void;
|
||||||
@@ -35,7 +36,8 @@ export const StepTwo = ({
|
|||||||
useState<TemplateInfo["details"]>();
|
useState<TemplateInfo["details"]>();
|
||||||
const [showValues, setShowValues] = useState<Record<string, boolean>>({});
|
const [showValues, setShowValues] = useState<Record<string, boolean>>({});
|
||||||
|
|
||||||
const { mutateAsync, isLoading } = api.ai.suggest.useMutation();
|
const { mutateAsync, isLoading, error, isError } =
|
||||||
|
api.ai.suggest.useMutation();
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
mutateAsync({
|
mutateAsync({
|
||||||
@@ -48,7 +50,6 @@ export const StepTwo = ({
|
|||||||
setSuggestions(data);
|
setSuggestions(data);
|
||||||
})
|
})
|
||||||
.catch((error) => {
|
.catch((error) => {
|
||||||
console.error("Error details:", error);
|
|
||||||
toast.error("Error generating suggestions");
|
toast.error("Error generating suggestions");
|
||||||
});
|
});
|
||||||
}, [templateInfo.userInput]);
|
}, [templateInfo.userInput]);
|
||||||
@@ -75,6 +76,7 @@ export const StepTwo = ({
|
|||||||
if (!selectedVariant) return;
|
if (!selectedVariant) return;
|
||||||
|
|
||||||
const updatedEnvVariables = [...selectedVariant.envVariables];
|
const updatedEnvVariables = [...selectedVariant.envVariables];
|
||||||
|
// @ts-ignore
|
||||||
updatedEnvVariables[index] = {
|
updatedEnvVariables[index] = {
|
||||||
...updatedEnvVariables[index],
|
...updatedEnvVariables[index],
|
||||||
[field]: value,
|
[field]: value,
|
||||||
@@ -151,7 +153,26 @@ export const StepTwo = ({
|
|||||||
],
|
],
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
if (isError) {
|
||||||
|
return (
|
||||||
|
<div className="flex flex-col items-center justify-center h-full space-y-4">
|
||||||
|
<Bot className="w-16 h-16 text-primary animate-pulse" />
|
||||||
|
<h2 className="text-2xl font-semibold animate-pulse">Error</h2>
|
||||||
|
<AlertBlock type="error">
|
||||||
|
{error?.message || "Error generating suggestions"}
|
||||||
|
</AlertBlock>
|
||||||
|
|
||||||
|
<Button
|
||||||
|
onClick={() =>
|
||||||
|
selectedVariant ? setSelectedVariant(undefined) : prevStep()
|
||||||
|
}
|
||||||
|
variant="outline"
|
||||||
|
>
|
||||||
|
{selectedVariant ? "Change Variant" : "Back"}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
if (isLoading) {
|
if (isLoading) {
|
||||||
return (
|
return (
|
||||||
<div className="flex flex-col items-center justify-center h-full space-y-4">
|
<div className="flex flex-col items-center justify-center h-full space-y-4">
|
||||||
|
|||||||
@@ -87,13 +87,20 @@ export const aiRouter = createTRPCRouter({
|
|||||||
aiId: z.string(),
|
aiId: z.string(),
|
||||||
input: z.string(),
|
input: z.string(),
|
||||||
serverId: z.string().optional(),
|
serverId: z.string().optional(),
|
||||||
}),
|
})
|
||||||
)
|
)
|
||||||
.mutation(async ({ ctx, input }) => {
|
.mutation(async ({ ctx, input }) => {
|
||||||
|
try {
|
||||||
return await suggestVariants({
|
return await suggestVariants({
|
||||||
...input,
|
...input,
|
||||||
adminId: ctx.user.adminId,
|
adminId: ctx.user.adminId,
|
||||||
});
|
});
|
||||||
|
} catch (error) {
|
||||||
|
throw new TRPCError({
|
||||||
|
code: "BAD_REQUEST",
|
||||||
|
message: error instanceof Error ? error?.message : `Error: ${error}`,
|
||||||
|
});
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
deploy: protectedProcedure
|
deploy: protectedProcedure
|
||||||
.input(deploySuggestionSchema)
|
.input(deploySuggestionSchema)
|
||||||
|
|||||||
Reference in New Issue
Block a user