Skip to content

Commit 3a7351d

Browse files
committed
Simplify error handling for plan creation
Error responses for plan creation have been streamlined in both backend and frontend. The backend now returns a concise error message for content safety violations, and the frontend no longer parses or customizes error details, instead displaying a generic error toast. This reduces complexity and improves consistency in user-facing error messages.
1 parent 520dfb6 commit 3a7351d

File tree

3 files changed

+11
-57
lines changed

3 files changed

+11
-57
lines changed

src/backend/v3/api/router.py

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -235,18 +235,7 @@ async def process_request(
235235
)
236236
raise HTTPException(
237237
status_code=400,
238-
detail={
239-
"error_type": "RAI_VALIDATION_FAILED",
240-
"message": "Content Safety Check Failed",
241-
"description": "Your request contains content that doesn't meet our safety guidelines. Please modify your request to ensure it's appropriate and try again.",
242-
"suggestions": [
243-
"Remove any potentially harmful, inappropriate, or unsafe content",
244-
"Use more professional and constructive language",
245-
"Focus on legitimate business or educational objectives",
246-
"Ensure your request complies with content policies",
247-
],
248-
"user_action": "Please revise your request and try again",
249-
},
238+
detail="Request contains content that doesn't meet our safety guidelines, try again.",
250239
)
251240

252241
authenticated_user = get_authenticated_user_details(request_headers=request.headers)
@@ -256,7 +245,7 @@ async def process_request(
256245
track_event_if_configured(
257246
"UserIdNotFound", {"status_code": 400, "detail": "no user"}
258247
)
259-
raise HTTPException(status_code=400, detail="no user")
248+
raise HTTPException(status_code=400, detail="no user found")
260249

261250
# if not input_task.team_id:
262251
# track_event_if_configured(

src/frontend/src/components/content/HomeInput.tsx

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -114,36 +114,19 @@ const HomeInput: React.FC<HomeInputProps> = ({
114114
dismissToast(id);
115115
}
116116
} catch (error: any) {
117+
console.log("Error creating plan:", error);
118+
let errorMessage = "Unable to create plan. Please try again.";
117119
dismissToast(id);
118120
// Check if this is an RAI validation error
119-
let errorDetail = null;
120121
try {
121-
// Try to parse the error detail if it's a string
122-
if (typeof error?.response?.data?.detail === 'string') {
123-
errorDetail = JSON.parse(error.response.data.detail);
124-
} else {
125-
errorDetail = error?.response?.data?.detail;
126-
}
122+
// errorDetail = JSON.parse(error);
123+
errorMessage = error?.message || errorMessage;
127124
} catch (parseError) {
128-
// If parsing fails, use the original error
129-
errorDetail = error?.response?.data?.detail;
125+
console.error("Error parsing error detail:", parseError);
130126
}
131127

132-
// Handle RAI validation errors - just show description as toast
133-
if (errorDetail?.error_type === 'RAI_VALIDATION_FAILED') {
134-
const description = errorDetail.description ||
135-
"Your request contains content that doesn't meet our safety guidelines. Please try rephrasing.";
136-
showToast(description, "error");
137-
} else {
138-
// Handle other errors with toast messages
139-
const errorMessage = errorDetail?.description ||
140-
errorDetail?.message ||
141-
error?.response?.data?.message ||
142-
error?.message ||
143-
"Something went wrong. Please try again.";
144-
145-
showToast(errorMessage, "error");
146-
}
128+
129+
showToast(errorMessage, "error");
147130
} finally {
148131
setInput("");
149132
setSubmitting(false);

src/frontend/src/services/TaskService.tsx

Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -195,28 +195,10 @@ export class TaskService {
195195
try {
196196
return await apiService.createPlan(inputTask);
197197
} catch (error: any) {
198+
198199
// You can customize this logic as needed
199200
let message = "Unable to create plan. Please try again.";
200-
if (error?.response?.data?.detail) {
201-
const detail = error.response.data.detail;
202-
if (typeof detail === 'string' && detail.includes('RAI_VALIDATION_FAILED')) {
203-
message = "Your request contains content that doesn't meet our safety guidelines. Please rephrase and try again.";
204-
} else if (detail.includes('quota') || detail.includes('limit')) {
205-
message = "Service is currently at capacity. Please try again in a few minutes.";
206-
} else if (detail.includes('unauthorized') || detail.includes('forbidden')) {
207-
message = "You don't have permission to create plans. Please contact your administrator.";
208-
} else {
209-
message = detail;
210-
}
211-
} else if (error?.response?.data?.message) {
212-
message = error.response.data.message;
213-
} else if (error?.message) {
214-
if (error.message.includes('Network Error') || error.message.includes('fetch')) {
215-
message = "Network error. Please check your connection and try again.";
216-
} else {
217-
message = error.message;
218-
}
219-
}
201+
220202
throw new Error(message);
221203
}
222204
}

0 commit comments

Comments
 (0)