diff --git a/src/database.py b/src/database.py index 0b62b6e..ff9790f 100644 --- a/src/database.py +++ b/src/database.py @@ -226,6 +226,7 @@ async def get_db() -> aiosqlite.Connection: db.row_factory = aiosqlite.Row await db.execute("PRAGMA journal_mode=WAL") await db.execute("PRAGMA foreign_keys=ON") + await db.execute("PRAGMA busy_timeout=5000") return db diff --git a/src/routers/incidents.py b/src/routers/incidents.py index 2d3d050..b05ab6a 100644 --- a/src/routers/incidents.py +++ b/src/routers/incidents.py @@ -218,8 +218,16 @@ async def delete_incident( detail="Nur der Ersteller kann diese Lage loeschen", ) - await db.execute("DELETE FROM incidents WHERE id = ?", (incident_id,)) - await db.commit() + try: + await db.execute("DELETE FROM incidents WHERE id = ?", (incident_id,)) + await db.commit() + except Exception as e: + if "database is locked" in str(e): + raise HTTPException( + status_code=status.HTTP_409_CONFLICT, + detail="Datenbank ist momentan beschaeftigt. Bitte in wenigen Sekunden erneut versuchen.", + ) + raise @router.get("/{incident_id}/articles")