fix some bugs and enhance error handling
This commit is contained in:
@@ -21,14 +21,13 @@ export function runMission(id) {
|
||||
"run_mission",
|
||||
mission
|
||||
);
|
||||
if (error) {
|
||||
throw new Error(message);
|
||||
if (!error) {
|
||||
await prisma.mission.update({
|
||||
where: { id },
|
||||
data: { result },
|
||||
});
|
||||
}
|
||||
const missionWithResult = prisma.mission.update({
|
||||
where: { id },
|
||||
data: { result },
|
||||
});
|
||||
return missionWithResult;
|
||||
return { result, error, message };
|
||||
} else {
|
||||
throw Error("Mission doest not exist");
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ load_dotenv()
|
||||
|
||||
process_type = {
|
||||
"SEQUENTIAL": Process.sequential,
|
||||
"HIERARTICAL": Process.hierarchical,
|
||||
"HIERARCHICAL": Process.hierarchical,
|
||||
}
|
||||
|
||||
tool_dict = {
|
||||
@@ -74,12 +74,7 @@ def run_mission(mission):
|
||||
)
|
||||
|
||||
result = crew.kickoff()
|
||||
return {
|
||||
"result": result
|
||||
}
|
||||
return {"result": result}
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return ({
|
||||
"error": True,
|
||||
"message": str(e)
|
||||
})
|
||||
return {"error": True, "message": str(e)}
|
||||
|
||||
@@ -50,6 +50,12 @@ const typeDefs = `#graphql
|
||||
result: String
|
||||
}
|
||||
|
||||
type RunMissionResult {
|
||||
result: String
|
||||
error: Boolean
|
||||
message: String
|
||||
}
|
||||
|
||||
enum MissionProcess {
|
||||
SEQUENTIAL
|
||||
HIERARCHICAL
|
||||
@@ -103,7 +109,7 @@ const typeDefs = `#graphql
|
||||
|
||||
deleteMission(id: Int!): DeleteOutput
|
||||
|
||||
runMission(id: Int!): Mission
|
||||
runMission(id: Int!): RunMissionResult
|
||||
}
|
||||
`;
|
||||
|
||||
|
||||
@@ -315,15 +315,23 @@ export default function MissionModal(props: {
|
||||
onClick={() => {
|
||||
handleRunMission()
|
||||
.then((missionData) => {
|
||||
setMissionResult(
|
||||
missionData.data.runMission.result
|
||||
);
|
||||
ReactSwal.fire({
|
||||
title: "Finished",
|
||||
text: "Mission finished successfully",
|
||||
icon: "success",
|
||||
});
|
||||
onRunMission();
|
||||
const { result, error, message } =
|
||||
missionData.data.runMission;
|
||||
if (!error) {
|
||||
setMissionResult(result);
|
||||
ReactSwal.fire({
|
||||
title: "Finished",
|
||||
text: "Mission finished successfully",
|
||||
icon: "success",
|
||||
});
|
||||
onRunMission();
|
||||
} else {
|
||||
ReactSwal.fire({
|
||||
title: "Error",
|
||||
text: message,
|
||||
icon: "error",
|
||||
});
|
||||
}
|
||||
})
|
||||
.catch((error) => {
|
||||
ReactSwal.fire({
|
||||
|
||||
@@ -259,23 +259,9 @@ export const DELETE_MISSION = gql`
|
||||
export const RUN_MISSION = gql`
|
||||
mutation RunMission($id: Int!) {
|
||||
runMission(id: $id) {
|
||||
id
|
||||
name
|
||||
crew {
|
||||
id
|
||||
role
|
||||
}
|
||||
tasks {
|
||||
name
|
||||
description
|
||||
agent {
|
||||
id
|
||||
role
|
||||
}
|
||||
}
|
||||
verbose
|
||||
process
|
||||
result
|
||||
error
|
||||
message
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
Reference in New Issue
Block a user