Compare commits
6 commits
main
...
chore/impr
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
fd2a629971 | ||
|
|
6c180891f9 | ||
|
|
8e4cdf4334 | ||
|
|
4977491966 | ||
|
|
bcfae9f291 | ||
|
|
440b4b0cf3 |
2 changed files with 30 additions and 17 deletions
|
|
@ -80,6 +80,24 @@ async def lifespan(app: FastAPI):
|
||||||
app = FastAPI(debug=app_environment != "prod", lifespan=lifespan)
|
app = FastAPI(debug=app_environment != "prod", lifespan=lifespan)
|
||||||
|
|
||||||
|
|
||||||
|
@app.middleware("http")
|
||||||
|
async def log_exceptions_middleware(request: Request, call_next):
|
||||||
|
try:
|
||||||
|
return await call_next(request)
|
||||||
|
except Exception as exc:
|
||||||
|
logger.error(
|
||||||
|
f"Unhandled exception in {request.method} {request.url.path}: "
|
||||||
|
f"{type(exc).__name__}: {str(exc)}"
|
||||||
|
)
|
||||||
|
return JSONResponse(
|
||||||
|
status_code=500,
|
||||||
|
content={
|
||||||
|
"message": "An internal server error occurred. Please check server logs for details.",
|
||||||
|
"path": str(request.url.path),
|
||||||
|
},
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# Read allowed origins from environment variable (comma-separated)
|
# Read allowed origins from environment variable (comma-separated)
|
||||||
CORS_ALLOWED_ORIGINS = os.getenv("CORS_ALLOWED_ORIGINS")
|
CORS_ALLOWED_ORIGINS = os.getenv("CORS_ALLOWED_ORIGINS")
|
||||||
if CORS_ALLOWED_ORIGINS:
|
if CORS_ALLOWED_ORIGINS:
|
||||||
|
|
|
||||||
|
|
@ -9,11 +9,8 @@ from cognee.modules.users.models import User
|
||||||
from cognee.modules.users.methods import get_authenticated_user
|
from cognee.modules.users.methods import get_authenticated_user
|
||||||
from cognee.shared.utils import send_telemetry
|
from cognee.shared.utils import send_telemetry
|
||||||
from cognee.modules.pipelines.models import PipelineRunErrored
|
from cognee.modules.pipelines.models import PipelineRunErrored
|
||||||
from cognee.shared.logging_utils import get_logger
|
|
||||||
from cognee import __version__ as cognee_version
|
from cognee import __version__ as cognee_version
|
||||||
|
|
||||||
logger = get_logger()
|
|
||||||
|
|
||||||
|
|
||||||
def get_add_router() -> APIRouter:
|
def get_add_router() -> APIRouter:
|
||||||
router = APIRouter()
|
router = APIRouter()
|
||||||
|
|
@ -54,7 +51,8 @@ def get_add_router() -> APIRouter:
|
||||||
|
|
||||||
## Error Codes
|
## Error Codes
|
||||||
- **400 Bad Request**: Neither datasetId nor datasetName provided
|
- **400 Bad Request**: Neither datasetId nor datasetName provided
|
||||||
- **409 Conflict**: Error during add operation
|
- **500 Internal Server Error**: Error during add operation (check logs for details)
|
||||||
|
- **420 Pipeline Error**: Pipeline execution failed with structured error details
|
||||||
- **403 Forbidden**: User doesn't have permission to add to dataset
|
- **403 Forbidden**: User doesn't have permission to add to dataset
|
||||||
|
|
||||||
## Notes
|
## Notes
|
||||||
|
|
@ -76,7 +74,6 @@ def get_add_router() -> APIRouter:
|
||||||
if not datasetId and not datasetName:
|
if not datasetId and not datasetName:
|
||||||
raise ValueError("Either datasetId or datasetName must be provided.")
|
raise ValueError("Either datasetId or datasetName must be provided.")
|
||||||
|
|
||||||
try:
|
|
||||||
add_run = await cognee_add(
|
add_run = await cognee_add(
|
||||||
data,
|
data,
|
||||||
datasetName,
|
datasetName,
|
||||||
|
|
@ -88,7 +85,5 @@ def get_add_router() -> APIRouter:
|
||||||
if isinstance(add_run, PipelineRunErrored):
|
if isinstance(add_run, PipelineRunErrored):
|
||||||
return JSONResponse(status_code=420, content=add_run.model_dump(mode="json"))
|
return JSONResponse(status_code=420, content=add_run.model_dump(mode="json"))
|
||||||
return add_run.model_dump()
|
return add_run.model_dump()
|
||||||
except Exception as error:
|
|
||||||
return JSONResponse(status_code=409, content={"error": str(error)})
|
|
||||||
|
|
||||||
return router
|
return router
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue