Commit 336fe219 authored by Romain Courteaud's avatar Romain Courteaud

slapos_json_rpc_api: fix error reporting

parent cd4db4d5
import json from erp5.component.document.JsonRpcAPIService import JsonRpcAPIError
software_instance = context class WrongReportedStateError(JsonRpcAPIError):
type = "SOFTWARE-INSTANCE-WRONG-REPORTED-STATE"
status = 403
logError = context.ERP5Site_logApiErrorAndReturn software_instance = context.jIOWebSection_getObjectFromData(data_dict)
castToStr = context.Base_castDictToXMLString castToStr = context.Base_castDictToXMLString
if "connection_parameters" in data_dict: if "connection_parameters" in data_dict:
...@@ -38,10 +40,7 @@ if "reported_state" in data_dict: ...@@ -38,10 +40,7 @@ if "reported_state" in data_dict:
error_log = data_dict.get("status_message", "") error_log = data_dict.get("status_message", "")
software_instance.setErrorStatus('while instanciating: %s' % error_log[-80:], reindex=1) software_instance.setErrorStatus('while instanciating: %s' % error_log[-80:], reindex=1)
else: else:
return logError( raise WrongReportedStateError("Unexcepected Reported State: %s" % reported_state)
error_name="SOFTWARE-INSTANCE-WRONG-REPORTED-STATE",
error_message="Unexcepected Reported State: %s" % reported_state,
)
if "requested_instance_list" in data_dict: if "requested_instance_list" in data_dict:
software_instance.updateRequestedInstanceList(data_dict["requested_instance_list"]) software_instance.updateRequestedInstanceList(data_dict["requested_instance_list"])
...@@ -52,10 +51,10 @@ if "title" in data_dict and data_dict["title"] != software_instance.getTitle(): ...@@ -52,10 +51,10 @@ if "title" in data_dict and data_dict["title"] != software_instance.getTitle():
comment="Rename %s into %s" % (software_instance.getTitle(), data_dict["title"]) comment="Rename %s into %s" % (software_instance.getTitle(), data_dict["title"])
) )
return json.dumps({ return {
"$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema", #"$schema": json_form.absolute_url().strip() + "/getOutputJSONSchema",
"reference": software_instance.getReference(), "reference": software_instance.getReference(),
"portal_type": "Software Instance", "portal_type": "Software Instance",
"date": DateTime().HTML4(), "date": DateTime().ISO8601(),
"success": "Done" "success": "Done"
}, indent=2) }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment