fix some bugs and enhance error handling

This commit is contained in:
Eng. Elias
2024-03-16 00:40:14 +04:00
parent 79cf073658
commit 7f2315e4fd
5 changed files with 35 additions and 41 deletions

View File

@@ -21,14 +21,13 @@ export function runMission(id) {
"run_mission", "run_mission",
mission mission
); );
if (error) { if (!error) {
throw new Error(message); await prisma.mission.update({
where: { id },
data: { result },
});
} }
const missionWithResult = prisma.mission.update({ return { result, error, message };
where: { id },
data: { result },
});
return missionWithResult;
} else { } else {
throw Error("Mission doest not exist"); throw Error("Mission doest not exist");
} }

View File

@@ -16,7 +16,7 @@ load_dotenv()
process_type = { process_type = {
"SEQUENTIAL": Process.sequential, "SEQUENTIAL": Process.sequential,
"HIERARTICAL": Process.hierarchical, "HIERARCHICAL": Process.hierarchical,
} }
tool_dict = { tool_dict = {
@@ -74,12 +74,7 @@ def run_mission(mission):
) )
result = crew.kickoff() result = crew.kickoff()
return { return {"result": result}
"result": result
}
except Exception as e: except Exception as e:
print(e) print(e)
return ({ return {"error": True, "message": str(e)}
"error": True,
"message": str(e)
})

View File

@@ -50,6 +50,12 @@ const typeDefs = `#graphql
result: String result: String
} }
type RunMissionResult {
result: String
error: Boolean
message: String
}
enum MissionProcess { enum MissionProcess {
SEQUENTIAL SEQUENTIAL
HIERARCHICAL HIERARCHICAL
@@ -103,7 +109,7 @@ const typeDefs = `#graphql
deleteMission(id: Int!): DeleteOutput deleteMission(id: Int!): DeleteOutput
runMission(id: Int!): Mission runMission(id: Int!): RunMissionResult
} }
`; `;

View File

@@ -315,15 +315,23 @@ export default function MissionModal(props: {
onClick={() => { onClick={() => {
handleRunMission() handleRunMission()
.then((missionData) => { .then((missionData) => {
setMissionResult( const { result, error, message } =
missionData.data.runMission.result missionData.data.runMission;
); if (!error) {
ReactSwal.fire({ setMissionResult(result);
title: "Finished", ReactSwal.fire({
text: "Mission finished successfully", title: "Finished",
icon: "success", text: "Mission finished successfully",
}); icon: "success",
onRunMission(); });
onRunMission();
} else {
ReactSwal.fire({
title: "Error",
text: message,
icon: "error",
});
}
}) })
.catch((error) => { .catch((error) => {
ReactSwal.fire({ ReactSwal.fire({

View File

@@ -259,23 +259,9 @@ export const DELETE_MISSION = gql`
export const RUN_MISSION = gql` export const RUN_MISSION = gql`
mutation RunMission($id: Int!) { mutation RunMission($id: Int!) {
runMission(id: $id) { runMission(id: $id) {
id
name
crew {
id
role
}
tasks {
name
description
agent {
id
role
}
}
verbose
process
result result
error
message
} }
} }
`; `;