Spaces:
Sleeping
Sleeping
dhruv575 commited on
Commit ·
baa6fc3
1
Parent(s): 5fdda3f
Better return statements
Browse files
controllers/log_controller.py
CHANGED
|
@@ -404,7 +404,7 @@ def classify_log_activities(current_user):
|
|
| 404 |
logger.error("Failed to save initial Log object.")
|
| 405 |
return jsonify({'message': 'Failed to create log entry'}), 500
|
| 406 |
log_id = new_log._id
|
| 407 |
-
logger.info(f"Log object created successfully with ID: {log_id}")
|
| 408 |
|
| 409 |
logger.info(f"Extracting activities with LLM for log {log_id}...")
|
| 410 |
activities_json = extract_activities(extracted_text)
|
|
@@ -509,12 +509,22 @@ def classify_log_activities(current_user):
|
|
| 509 |
else:
|
| 510 |
logger.error(f"Could not find Log {log_id} to update with incident IDs.")
|
| 511 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 512 |
logger.info("Successfully processed upload & classification request. Returning 200 OK.")
|
| 513 |
return jsonify({
|
| 514 |
'message': 'Log created, activities extracted and classified, incidents created.',
|
| 515 |
-
'log':
|
| 516 |
-
'classified_activities': classified_activities_output,
|
| 517 |
-
'extracted_text': extracted_text
|
| 518 |
}), 200
|
| 519 |
|
| 520 |
except Exception as e:
|
|
|
|
| 404 |
logger.error("Failed to save initial Log object.")
|
| 405 |
return jsonify({'message': 'Failed to create log entry'}), 500
|
| 406 |
log_id = new_log._id
|
| 407 |
+
logger.info(f"Log object created and saved successfully with ID: {log_id}")
|
| 408 |
|
| 409 |
logger.info(f"Extracting activities with LLM for log {log_id}...")
|
| 410 |
activities_json = extract_activities(extracted_text)
|
|
|
|
| 509 |
else:
|
| 510 |
logger.error(f"Could not find Log {log_id} to update with incident IDs.")
|
| 511 |
|
| 512 |
+
# --- Log right before return ---
|
| 513 |
+
try:
|
| 514 |
+
log_dict_to_return = new_log.to_dict()
|
| 515 |
+
logger.info(f"Preparing to return Log object: {log_dict_to_return}")
|
| 516 |
+
except Exception as to_dict_err:
|
| 517 |
+
logger.error(f"Error calling new_log.to_dict() before return: {to_dict_err}")
|
| 518 |
+
# Optionally return an error here if to_dict fails
|
| 519 |
+
return jsonify({'message': 'Internal error preparing log data for response.'}), 500
|
| 520 |
+
# --- End Log right before return ---
|
| 521 |
+
|
| 522 |
logger.info("Successfully processed upload & classification request. Returning 200 OK.")
|
| 523 |
return jsonify({
|
| 524 |
'message': 'Log created, activities extracted and classified, incidents created.',
|
| 525 |
+
'log': log_dict_to_return, # Use the logged dictionary
|
| 526 |
+
'classified_activities': classified_activities_output,
|
| 527 |
+
'extracted_text': extracted_text
|
| 528 |
}), 200
|
| 529 |
|
| 530 |
except Exception as e:
|