Use Axios for POST request
This commit is contained in:
Generated
+372
-3
File diff suppressed because it is too large
Load Diff
@@ -40,6 +40,7 @@
|
|||||||
"@radix-ui/react-toggle-group": "^1.1.10",
|
"@radix-ui/react-toggle-group": "^1.1.10",
|
||||||
"@radix-ui/react-tooltip": "^1.2.7",
|
"@radix-ui/react-tooltip": "^1.2.7",
|
||||||
"@tanstack/react-query": "^5.83.0",
|
"@tanstack/react-query": "^5.83.0",
|
||||||
|
"axios": "^1.12.2",
|
||||||
"class-variance-authority": "^0.7.1",
|
"class-variance-authority": "^0.7.1",
|
||||||
"clsx": "^2.1.1",
|
"clsx": "^2.1.1",
|
||||||
"cmdk": "^1.1.1",
|
"cmdk": "^1.1.1",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
import axios from "axios";
|
||||||
import { Download, Sparkles } from "lucide-react";
|
import { Download, Sparkles } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import {
|
import {
|
||||||
@@ -71,27 +72,21 @@ export const OpinionDialog = ({
|
|||||||
setIsGenerating(true);
|
setIsGenerating(true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await axios.post(
|
||||||
"https://prod-hgtx-intelligence-n8n.hgtx.com.br/webhook/codex/gepam/parecer-tecnico",
|
"https://prod-hgtx-intelligence-n8n.hgtx.com.br/webhook/codex/gepam/parecer-tecnico",
|
||||||
{
|
{
|
||||||
method: "POST",
|
|
||||||
headers: {
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
body: JSON.stringify({
|
|
||||||
titulo: title,
|
titulo: title,
|
||||||
categoria: category,
|
categoria: category,
|
||||||
instrucoes: instructions,
|
instrucoes: instructions,
|
||||||
}),
|
},
|
||||||
|
{
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!response.ok) {
|
const content = response.data.parecer || response.data.content || JSON.stringify(response.data, null, 2);
|
||||||
throw new Error("Erro ao gerar parecer");
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const content = data.parecer || data.content || JSON.stringify(data, null, 2);
|
|
||||||
|
|
||||||
setGeneratedContent(content);
|
setGeneratedContent(content);
|
||||||
setIsGenerating(false);
|
setIsGenerating(false);
|
||||||
@@ -113,9 +108,20 @@ export const OpinionDialog = ({
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Erro ao gerar parecer:", error);
|
console.error("Erro ao gerar parecer:", error);
|
||||||
setIsGenerating(false);
|
setIsGenerating(false);
|
||||||
|
|
||||||
|
let errorMessage = "Não foi possível gerar o parecer. Tente novamente.";
|
||||||
|
|
||||||
|
if (axios.isAxiosError(error)) {
|
||||||
|
if (error.response) {
|
||||||
|
errorMessage = error.response.data?.message || `Erro do servidor: ${error.response.status}`;
|
||||||
|
} else if (error.request) {
|
||||||
|
errorMessage = "Sem resposta do servidor. Verifique sua conexão.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
toast({
|
toast({
|
||||||
title: "Erro ao gerar parecer",
|
title: "Erro ao gerar parecer",
|
||||||
description: "Não foi possível gerar o parecer. Tente novamente.",
|
description: errorMessage,
|
||||||
variant: "destructive",
|
variant: "destructive",
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user