AOSSIE-Org / AOSSIE-Org/PictoPy

Refactor: Improve SQLite error handling and integrate logger in albums database layer

未關閉
#1,340 7 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
283
分支
679
平均合併
7 天 2 小時
30 天內合併 PR
3

描述

### Describe the bug or improvement
The database module `backend/app/database/albums.py` currently executes SQLite operations directly without wrapping them in `try...except sqlite3.Error` blocks. When database queries fail, the errors are raised silently to the API layer without being logged locally. This is inconsistent with the rest of the database modules (like `images.py`, `folders.py`, `faces.py`, and `metadata.py`), which have been updated to capture, log, and handle SQLite exceptions using the project's standard logger.

Additionally, the route file `backend/app/routes/albums.py` should catch these database errors and log them, and use `except HTTPException: raise` to prevent catching and hiding explicit HTTP exceptions within `except Exception` blocks.

### Proposed Solution
1. In `backend/app/database/albums.py`:
- Import `get_logger` from `app.logging.setup_logging` and initialize the logger.
- Wrap SQL execution blocks (like `cursor.execute`) in `try...except sqlite3.Error as e:` blocks.
- Log the database errors with `logger.error(...)` before re-raising.
2. In `backend/app/routes/albums.py`:
- Add `except HTTPException: raise` to prevent wrapping HTTP status codes in standard 500 errors.
- Log any unexpected errors.

This is a good first issue for backend cleanup!

貢獻指南

開啟貢獻指南

評估

這個 Issue 還沒有評估資料。

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。