Skip to content

Drop in a screenshot and convert it to clean code (HTML/Tailwind/React/Vue)

Python

refactor to get .get()

Abi Raja0f731598ddf6
diff --git a/backend/routes/generate_code.py b/backend/routes/generate_code.py
index 6d4f0e41..055853f5 100644
--- a/backend/routes/generate_code.py
+++ b/backend/routes/generate_code.py
@@ -107,13 +107,11 @@ async def stream_code(websocket: WebSocket):
print("Received params")
- # Read the code config settings (stack) from the request. Fall back to default if not provided.
- generated_code_config = ""
- if "generatedCodeConfig" in params and params["generatedCodeConfig"]:
- generated_code_config = params["generatedCodeConfig"]
+ # Read the code config settings (stack) from the request.
+ generated_code_config = params.get("generatedCodeConfig", "")
if not generated_code_config in get_args(Stack):
await throw_error(f"Invalid generated code config: {generated_code_config}")
- return
+ raise Exception(f"Invalid generated code config: {generated_code_config}")
# Cast the variable to the Stack type
valid_stack = cast(Stack, generated_code_config)