Description
Several backend API routes are currently catching database connection or query failures and silently swallowing them. Instead of propagating the error or returning an appropriate HTTP 500 Internal Server Error status, these endpoints return a 200 OK status with empty or fallback data.
For example, endpoints like /api/local-coding-stats and /api/user/settings fail silently when the Supabase database is unreachable, responding as if the request succeeded. This fundamentally breaks error handling on the frontend (since fetch requests interpret the 200 as a success) and makes debugging backend issues incredibly frustrating.
Expected Behavior
- Any unhandled exceptions or database connection failures within an API route should result in a
500 Internal Server Error response.
- The frontend should be able to appropriately catch these non-2xx responses and display a meaningful error message to the user (or trigger retry logic).
- API routes should only return
200 OK when the underlying operation (like fetching or updating user settings) has verifiably succeeded.
Steps to Reproduce
- Intentionally break the local database connection (e.g., provide an invalid
SUPABASE_URL or stop the database service).
- Attempt to fetch local coding stats by calling
/api/local-coding-stats or try to update user settings.
- Observe the network tab: the request returns a
200 OK with an empty object or null data.
- Run the API test suite (
npm run test test/local-coding-stats.test.ts) which asserts and exposes this exact improper behavior.
Suggested Fix
- Audit the
catch blocks within the src/app/api/ routes.
- Replace returns like
NextResponse.json({ data: [] }, { status: 200 }) inside catch blocks with NextResponse.json({ error: "Internal Server Error" }, { status: 500 }).
- Update the associated unit tests to assert that a
500 status code is returned on database failures.
Description
Several backend API routes are currently catching database connection or query failures and silently swallowing them. Instead of propagating the error or returning an appropriate HTTP 500 Internal Server Error status, these endpoints return a
200 OKstatus with empty or fallback data.For example, endpoints like
/api/local-coding-statsand/api/user/settingsfail silently when the Supabase database is unreachable, responding as if the request succeeded. This fundamentally breaks error handling on the frontend (sincefetchrequests interpret the200as a success) and makes debugging backend issues incredibly frustrating.Expected Behavior
500 Internal Server Errorresponse.200 OKwhen the underlying operation (like fetching or updating user settings) has verifiably succeeded.Steps to Reproduce
SUPABASE_URLor stop the database service)./api/local-coding-statsor try to update user settings.200 OKwith an empty object or null data.npm run test test/local-coding-stats.test.ts) which asserts and exposes this exact improper behavior.Suggested Fix
catchblocks within thesrc/app/api/routes.NextResponse.json({ data: [] }, { status: 200 })inside catch blocks withNextResponse.json({ error: "Internal Server Error" }, { status: 500 }).500status code is returned on database failures.