Skip to content

Commit

Permalink
web app handles pydantic validation error (#461)
Browse files Browse the repository at this point in the history
  • Loading branch information
ykeremy committed Jun 12, 2024
1 parent 8e21c8b commit 5d134d5
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion skyvern/forge/api_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
from typing import Awaitable, Callable

import structlog
from fastapi import APIRouter, FastAPI, Response
from fastapi import APIRouter, FastAPI, Response, status
from fastapi.middleware.cors import CORSMiddleware
from fastapi.responses import JSONResponse
from pydantic import ValidationError
from starlette.requests import HTTPConnection, Request
from starlette_context.middleware import RawContextMiddleware
from starlette_context.plugins.base import Plugin
Expand Down Expand Up @@ -78,6 +79,10 @@ def start_scheduler() -> None:
async def handle_skyvern_http_exception(request: Request, exc: SkyvernHTTPException) -> JSONResponse:
return JSONResponse(status_code=exc.status_code, content={"detail": exc.message})

@app.exception_handler(ValidationError)
async def handle_pydantic_validation_error(request: Request, exc: ValidationError) -> JSONResponse:
return JSONResponse(status_code=status.HTTP_422_UNPROCESSABLE_ENTITY, content={"detail": str(exc)})

@app.exception_handler(Exception)
async def unexpected_exception(request: Request, exc: Exception) -> JSONResponse:
LOG.exception("Unexpected error in agent server.", exc_info=exc)
Expand Down

0 comments on commit 5d134d5

Please sign in to comment.