Skip to content

Commit efe2a90

Browse files
committed
Additional return codes durig failure in register gateway
Signed-off-by: Madhav Kandukuri <[email protected]>
1 parent 7652177 commit efe2a90

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

mcpgateway/admin.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
ToolRead,
4949
ToolUpdate,
5050
)
51-
from mcpgateway.services.gateway_service import GatewayService, GatewayConnectionError
51+
from mcpgateway.services.gateway_service import GatewayConnectionError, GatewayService
5252
from mcpgateway.services.prompt_service import PromptService
5353
from mcpgateway.services.resource_service import ResourceService
5454
from mcpgateway.services.root_service import RootService
@@ -769,6 +769,12 @@ async def admin_add_gateway(request: Request, db: Session = Depends(get_db), use
769769
except Exception as ex:
770770
if isinstance(ex, GatewayConnectionError):
771771
return RedirectResponse(f"{root_path}/admin#gateways", status_code=502)
772+
elif isinstance(ex, ValueError):
773+
return RedirectResponse(f"{root_path}/admin#gateways", status_code=400)
774+
elif isinstance(ex, RuntimeError):
775+
return RedirectResponse(f"{root_path}/admin#gateways", status_code=500)
776+
else:
777+
return RedirectResponse(f"{root_path}/admin#gateways", status_code=500)
772778

773779

774780
@admin_router.post("/gateways/{gateway_id}/edit")

mcpgateway/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,12 @@ async def register_gateway(
15101510
except Exception as ex:
15111511
if isinstance(ex, GatewayConnectionError):
15121512
return JSONResponse(content={"message": "Unable to connect to gateway"}, status_code=502)
1513+
elif isinstance(ex, ValueError):
1514+
return JSONResponse(content={"message": "Unable to process input"}, status_code=400)
1515+
elif isinstance(ex, RuntimeError):
1516+
return JSONResponse(content={"message": "Error during execution"}, status_code=500)
1517+
else:
1518+
return JSONResponse(content={"message": "Unexpected error"}, status_code=500)
15131519

15141520

15151521
@gateway_router.get("/{gateway_id}", response_model=GatewayRead)

0 commit comments

Comments
 (0)