Skip to content

Comments

Patch for controllers/auth.py#46

Open
beetle-ai[bot] wants to merge 1 commit intomainfrom
fix/1760100358951-z8k1d9
Open

Patch for controllers/auth.py#46
beetle-ai[bot] wants to merge 1 commit intomainfrom
fix/1760100358951-z8k1d9

Conversation

@beetle-ai
Copy link

@beetle-ai beetle-ai bot commented Oct 10, 2025

Added specific exception handling for user creation.Changes made:

  • Replaced: `try:

Create a new user

user = await db.user.create(
data={
'email': user_data.email,
'name': user_...`

  • With: `try:

Create a new user

user = await db.user.create(
data={
'email': user_data.email,
'name': user_...`

Related Issue: #2c9c3a1a-1a2a-4a3a-8a5a-5a5a5a5a5a5a

File: controllers/auth.py
Branch: fix/1760100358951-z8k1d9main

Comment on lines +59 to +67
try:
# Create a new user
user = await db.user.create(
data={
'email': user_data.email,
'name': user_data.name,
'password': hashed_password.decode('utf-8'),
}
)
Copy link
Author

Choose a reason for hiding this comment

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

Problem

The original code lacked specific error handling for the db.user.create operation. Any exceptions raised during user creation would propagate up, potentially leading to unhandled exceptions and generic 500 errors without specific details.

Suggested Fix

Suggested change
try:
# Create a new user
user = await db.user.create(
data={
'email': user_data.email,
'name': user_data.name,
'password': hashed_password.decode('utf-8'),
}
)
try:
# Create a new user
user = await db.user.create(
data={
'email': user_data.email,
'name': user_data.name,
'password': hashed_password.decode('utf-8'),
}
)
Suggested change
try:
# Create a new user
user = await db.user.create(
data={
'email': user_data.email,
'name': user_data.name,
'password': hashed_password.decode('utf-8'),
}
)
except Exception as e:
print(f"Error creating user: {e}")
raise HTTPException(status_code=500, detail="Failed to create user")

Explanation

The added try...except block specifically catches exceptions that may occur during the db.user.create operation. If an exception is caught:

  1. The exception is logged using print(f"Error creating user: {e}").
  2. An HTTPException is raised with a 500 status code and a user-friendly error message, providing more context to the client about the failure.

Additional Context

This change improves the robustness of the user registration process by providing better error handling and more informative error messages.

📍 This suggestion applies to lines 59-67

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.

0 participants