Skip to content

Commit 9108ee1

Browse files
authored
Refactor(API): fixed exception handling issues (#92)
1 parent bb98f56 commit 9108ee1

File tree

3 files changed

+15
-302
lines changed

3 files changed

+15
-302
lines changed

.github/workflows/commit-convention-linter.yml

Lines changed: 0 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,3 @@
1-
# name: PR Commit Convention Linter
2-
3-
# on:
4-
# pull_request:
5-
# types: [opened, synchronize, reopened]
6-
7-
# permissions:
8-
# pull-requests: write
9-
10-
# jobs:
11-
# commit-lint:
12-
# runs-on: ubuntu-latest
13-
14-
# steps:
15-
16-
# - name: Minimal Git clone without actions/checkout
17-
# run: |
18-
# git init
19-
# git remote add origin https://github.com/${{ github.repository }}.git
20-
# git fetch origin ${{ github.event.pull_request.head.ref }} --depth=1
21-
# git checkout FETCH_HEAD
22-
23-
24-
# - name: Install GitHub CLI
25-
# run: |
26-
# sudo apt-get update
27-
# sudo apt-get install -y gh
28-
29-
# - name: Get latest commit message
30-
# id: get_commit
31-
# run: |
32-
# git log -1 --pretty=format:"%s" > commit.txt
33-
34-
# - name: Validate commit message
35-
# id: validate
36-
# run: |
37-
# line=$(cat commit.txt)
38-
# echo "Checking commit: $line"
39-
40-
# # 메시지 길이 확인 (50자 초과면 경고)
41-
# if [[ ${#line} -gt 72 ]]; then
42-
# echo "::warning::⚠️ Commit message is longer than 72 characters."
43-
# fi
44-
45-
# # 정규식: 타입(scope): 메시지 (소문자 시작, 마침표 금지)
46-
# pattern='^(Feat|Fix|Docs|Style|Refactor|Test|Chore|Ci|Perf|Build)(\([a-zA-Z0-9_-]+\))?: [a-z][^\.]{0,69}$'
47-
48-
# if ! [[ "$line" =~ $pattern ]] && ! [[ "$line" =~ ^Merge.* ]]; then
49-
# echo "::error::❌ Invalid commit message: $line"
50-
# echo "invalid=1" >> $GITHUB_OUTPUT
51-
# else
52-
# echo "invalid=0" >> $GITHUB_OUTPUT
53-
# fi
54-
55-
# - name: Comment on PR if invalid
56-
# if: steps.validate.outputs.invalid == '1'
57-
# run: |
58-
# gh pr comment "$PR_NUMBER" --body "🚫 One or more commit messages in this PR **do not follow the commit convention.**
59-
60-
# Please revise them to match the format: \`Feat(actions): add something cool\`
61-
62-
# 📘 See our [Wiki](https://github.com/khyeonm/2025_Advanced_Programming/wiki/Git-Commit-Convention) for details.
63-
64-
# Thank you!"
65-
66-
# env:
67-
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
68-
# PR_NUMBER: ${{ github.event.pull_request.number }}
69-
701
name: PR Commit Convention Linter
712

723
on:

backend/API/guide.txt

Lines changed: 0 additions & 232 deletions
This file was deleted.

backend/API/main.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
from fastapi.middleware.cors import CORSMiddleware
77
from sqlalchemy import text
88
from functools import wraps
9+
import logging
10+
11+
# --- logger 설정 ---
12+
logging.basicConfig(level=logging.INFO)
13+
logger = logging.getLogger(__name__)
14+
15+
916

1017
# --- Factory Pattern ---
1118
class RequestFactory:
@@ -28,8 +35,15 @@ def safe_handler(func):
2835
def wrapper(*args, **kwargs):
2936
try:
3037
return func(*args, **kwargs)
38+
except ValueError as ve:
39+
logger.warning(f"400 Bad Request: {ve}")
40+
raise HTTPException(status_code=400, detail=str(ve))
41+
except KeyError as ke:
42+
logger.warning(f"404 Not Found: {ke}")
43+
raise HTTPException(status_code=404, detail=f"Not Found: {ke}")
3144
except Exception as e:
32-
raise HTTPException(status_code=500, detail=str(e))
45+
logger.error(f"500 Internal Server Error: {e}", exc_info=True)
46+
raise HTTPException(status_code=500, detail="Internal Server Error")
3347
return wrapper
3448

3549
# --- FastAPI ---

0 commit comments

Comments
 (0)