generated from cording12/next-fast-turbo
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
refactor: improve logging and code quality #537
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ankitpasayat
wants to merge
1
commit into
MODSetter:main
Choose a base branch
from
ankitpasayat:refactor/logging-and-code-quality
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,612
−348
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| import logging | ||
| import os | ||
| from pathlib import Path | ||
|
|
||
|
|
@@ -26,6 +27,8 @@ | |
| from app.users import current_active_user | ||
| from app.utils.rbac import check_permission | ||
|
|
||
| logger = logging.getLogger(__name__) | ||
|
|
||
| router = APIRouter() | ||
|
|
||
|
|
||
|
|
@@ -54,21 +57,24 @@ async def create_podcast( | |
| return db_podcast | ||
| except HTTPException as he: | ||
| raise he | ||
| except IntegrityError: | ||
| except IntegrityError as e: | ||
| await session.rollback() | ||
| logger.warning("Podcast creation failed due to integrity error: %s", e) | ||
| raise HTTPException( | ||
| status_code=400, | ||
| detail="Podcast creation failed due to constraint violation", | ||
| ) from None | ||
| except SQLAlchemyError: | ||
| except SQLAlchemyError as e: | ||
| await session.rollback() | ||
| logger.error("Database error while creating podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="Database error occurred while creating podcast" | ||
| ) from None | ||
| except Exception: | ||
| except Exception as e: | ||
| await session.rollback() | ||
|
||
| logger.error("Unexpected error while creating podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="An unexpected error occurred" | ||
| status_code=500, detail="An unexpected error occurred while creating podcast" | ||
| ) from None | ||
|
|
||
|
|
||
|
|
@@ -115,10 +121,16 @@ async def read_podcasts( | |
| return result.scalars().all() | ||
| except HTTPException: | ||
| raise | ||
| except SQLAlchemyError: | ||
| except SQLAlchemyError as e: | ||
| logger.error("Database error while fetching podcasts: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="Database error occurred while fetching podcasts" | ||
| ) from None | ||
| except Exception as e: | ||
| logger.error("Unexpected error while fetching podcasts: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="An unexpected error occurred while fetching podcasts" | ||
| ) from None | ||
|
|
||
|
|
||
| @router.get("/podcasts/{podcast_id}", response_model=PodcastRead) | ||
|
|
@@ -153,10 +165,16 @@ async def read_podcast( | |
| return podcast | ||
| except HTTPException as he: | ||
| raise he | ||
| except SQLAlchemyError: | ||
| except SQLAlchemyError as e: | ||
| logger.error("Database error while fetching podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="Database error occurred while fetching podcast" | ||
| ) from None | ||
| except Exception as e: | ||
| logger.error("Unexpected error while fetching podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="An unexpected error occurred while fetching podcast" | ||
| ) from None | ||
|
|
||
|
|
||
| @router.put("/podcasts/{podcast_id}", response_model=PodcastRead) | ||
|
|
@@ -199,11 +217,18 @@ async def update_podcast( | |
| raise HTTPException( | ||
| status_code=400, detail="Update failed due to constraint violation" | ||
| ) from None | ||
| except SQLAlchemyError: | ||
| except SQLAlchemyError as e: | ||
| await session.rollback() | ||
| logger.error("Database error while updating podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="Database error occurred while updating podcast" | ||
| ) from None | ||
| except Exception as e: | ||
| await session.rollback() | ||
| logger.error("Unexpected error while updating podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="An unexpected error occurred while updating podcast" | ||
| ) from None | ||
|
|
||
|
|
||
| @router.delete("/podcasts/{podcast_id}", response_model=dict) | ||
|
|
@@ -237,11 +262,18 @@ async def delete_podcast( | |
| return {"message": "Podcast deleted successfully"} | ||
| except HTTPException as he: | ||
| raise he | ||
| except SQLAlchemyError: | ||
| except SQLAlchemyError as e: | ||
| await session.rollback() | ||
| logger.error("Database error while deleting podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="Database error occurred while deleting podcast" | ||
| ) from None | ||
| except Exception as e: | ||
| await session.rollback() | ||
| logger.error("Unexpected error while deleting podcast: %s", e, exc_info=True) | ||
| raise HTTPException( | ||
| status_code=500, detail="An unexpected error occurred while deleting podcast" | ||
| ) from None | ||
|
|
||
|
|
||
| async def generate_chat_podcast_with_new_session( | ||
|
|
@@ -260,9 +292,7 @@ async def generate_chat_podcast_with_new_session( | |
| session, chat_id, search_space_id, user_id, podcast_title, user_prompt | ||
| ) | ||
| except Exception as e: | ||
| import logging | ||
|
|
||
| logging.error(f"Error generating podcast from chat: {e!s}") | ||
| logger.error("Error generating podcast from chat: %s", e, exc_info=True) | ||
|
|
||
|
|
||
| @router.post("/podcasts/generate") | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Import of 'refresh_airtable_token' is not used.