enhancing error handling

This commit is contained in:
Eng. Elias
2024-03-15 11:31:14 +04:00
parent 8615f106d6
commit 7a886fa31a
6 changed files with 35 additions and 17 deletions

View File

@@ -16,7 +16,14 @@ export function runMission(id) {
include: { crew: true }, include: { crew: true },
}); });
if (mission) { if (mission) {
const result = await py.call(pymodule, "run_mission", mission); const { result, error, message } = await py.call(
pymodule,
"run_mission",
mission
);
if (error) {
throw new Error(message);
}
const missionWithResult = prisma.mission.update({ const missionWithResult = prisma.mission.update({
where: { id }, where: { id },
data: { result }, data: { result },

View File

@@ -74,6 +74,12 @@ def run_mission(mission):
) )
result = crew.kickoff() result = crew.kickoff()
return result return {
"result": result
}
except Exception as e: except Exception as e:
print(e) print(e)
return ({
"error": True,
"message": str(e)
})

View File

@@ -6,7 +6,7 @@ import { Mission } from "@/types/mission";
import { GET_MISSIONS } from "@/utils/graphql_queries"; import { GET_MISSIONS } from "@/utils/graphql_queries";
import { useQuery } from "@apollo/client"; import { useQuery } from "@apollo/client";
import { Icon } from "@iconify/react/dist/iconify.js"; import { Icon } from "@iconify/react/dist/iconify.js";
import { Button, IconButton } from "@material-tailwind/react"; import { Alert, Button, IconButton } from "@material-tailwind/react";
import { useState } from "react"; import { useState } from "react";
const MissionsPage = () => { const MissionsPage = () => {
@@ -30,6 +30,20 @@ const MissionsPage = () => {
); );
} }
if (error) {
return (
<div className="w-full">
<Alert
color="yellow"
icon={<Icon icon="material-symbols:warning-outline" fontSize={26} />}
className="w-fit"
>
{error?.message ?? "An error occurred."}
</Alert>
</div>
);
}
return ( return (
<div> <div>
<div> <div>

View File

@@ -292,7 +292,7 @@ export default function MissionModal(props: {
</div> </div>
) : ( ) : (
<div> <div>
{mission?.tasks ? ( {mission?.tasks.length > 0 ? (
<div> <div>
<TasksAccordion tasks={mission.tasks} /> <TasksAccordion tasks={mission.tasks} />
</div> </div>
@@ -309,7 +309,9 @@ export default function MissionModal(props: {
<div className="my-3"> <div className="my-3">
<Button <Button
color="blue" color="blue"
disabled={runMissionLoading} disabled={
runMissionLoading || mission?.tasks.length === 0
}
onClick={() => { onClick={() => {
handleRunMission() handleRunMission()
.then((missionData) => { .then((missionData) => {

View File

@@ -196,18 +196,6 @@ function NewMissionModal(props: {
theme={selectTheme} theme={selectTheme}
/> />
</div> </div>
<div className="mb-4">
<label className="font-bold text-lg">Tasks:</label>
<div>
<MissionTaskEditor
mission={tempMission!}
agents={agentsData?.agents}
onMissionChange={(mission: Mission) => {
setTempMission(mission);
}}
/>
</div>
</div>
</div> </div>
</TEModalBody> </TEModalBody>

View File

@@ -22,6 +22,7 @@ export function makeApolloClient() {
return new NextSSRApolloClient({ return new NextSSRApolloClient({
cache: new NextSSRInMemoryCache(), cache: new NextSSRInMemoryCache(),
queryDeduplication: false,
link: link:
typeof window === "undefined" typeof window === "undefined"
? ApolloLink.from([ ? ApolloLink.from([