Skip to content

Jayden+aaron v2 3172025#18

Open
aarondtrng wants to merge 5 commits intodevfrom
jayden+aaron_V2_3172025
Open

Jayden+aaron v2 3172025#18
aarondtrng wants to merge 5 commits intodevfrom
jayden+aaron_V2_3172025

Conversation

@aarondtrng
Copy link
Copy Markdown

error handling for db

Comment on lines +59 to +62
except sqlite3.Error as e:
if(isinstance(e,ConnectionError)):
raise ConnectionError(f"Error when connecting to database: {str(e)}")
raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can do something like this which makes it more readable

Suggested change
except sqlite3.Error as e:
if(isinstance(e,ConnectionError)):
raise ConnectionError(f"Error when connecting to database: {str(e)}")
raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}")
except ConnectionError as e:
raise ConnectionError(f"Error when connecting to database: {str(e)}")
except Exception as e:
raise DatabaseError(f"Database error when fetching snack {sku}: {str(e)}")

Comment on lines +102 to +115
if not isinstance(snack.sku, str):
raise RecordNotFoundError(f"{snack.sku} is not a string")
if not isinstance(snack.name, str):
raise RecordNotFoundError(f"{snack.name} is not a string")
if not isinstance(snack.quantity, int):
raise RecordNotFoundError(f"{snack.quantity} is not an int")
if not isinstance(snack.price, float):
raise RecordNotFoundError(f"{snack.price} is not a float")
if not isinstance(snack.description, str):
raise RecordNotFoundError(f"{snack.description} is not a string")
if not isinstance(snack.category, str):
raise RecordNotFoundError(f"{snack.category} is not a string")
if not isinstance(snack.photo_url, str):
raise RecordNotFoundError(f"{snack.photo_url} is not a string")
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need to check the types here because the Pydantic models should be handling that for us.

@aarondtrng aarondtrng requested a review from NicholasLe04 March 21, 2025 02:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants