Skip to content

Commit 17e857b

Browse files
jx453331958claude
andcommitted
fix: add SQLite busy_timeout and detailed error messages
- Set busy_timeout=5000ms to handle concurrent write contention instead of failing immediately with SQLITE_BUSY - Return actual error message in usage report API response to help diagnose server-side failures Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 05d670d commit 17e857b

2 files changed

Lines changed: 5 additions & 2 deletions

File tree

src/app/api/usage/report/route.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ export async function POST(request: NextRequest) {
8484
skipped,
8585
});
8686
} catch (error) {
87-
console.error('Error reporting usage:', error);
88-
return NextResponse.json({ error: 'Internal server error' }, { status: 500 });
87+
const message = error instanceof Error ? error.message : String(error);
88+
console.error('Error reporting usage:', message);
89+
return NextResponse.json({ error: `Internal server error: ${message}` }, { status: 500 });
8990
}
9091
}

src/lib/db.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ function getDatabase(): Database.Database {
2121

2222
// Enable WAL mode for better concurrent access
2323
db.pragma('journal_mode = WAL');
24+
// Wait up to 5 seconds when database is locked instead of failing immediately
25+
db.pragma('busy_timeout = 5000');
2426

2527
// Initialize schema on first access
2628
initializeDatabase();

0 commit comments

Comments
 (0)