Skip to content

Commit

Permalink
fix: 修改返回判断 #7626
Browse files Browse the repository at this point in the history
  • Loading branch information
guohelu committed Dec 10, 2024
1 parent 3f16485 commit 5877bb6
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions gcloud/contrib/template_market/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,14 @@ def retrieve(self, request, *args, **kwargs):
)
url = self._get_market_routing(f"sre_scene/flow_template_scene/{template_shared_obj.scene_instance_id}/")
result = requests.get(url=url)
if not result.status_code == 200:
response_data = result.json()
if not response_data["result"]:
logging.exception(f"Get template information from market failed, error code: {result.status_code}")
return Response(
{"result": False, "message": "Get template information failed", "code": err_code.OPERATION_FAIL.code}
)

return Response({"result": True, "data": result.json(), "code": err_code.SUCCESS.code})
return Response({"result": True, "data": response_data, "code": err_code.SUCCESS.code})

@swagger_auto_schema(request_body=TemplateSharedRecordSerializer)
def create(self, request, *args, **kwargs):
Expand Down Expand Up @@ -102,15 +103,15 @@ def create(self, request, *args, **kwargs):
}
try:
result = requests.post(url, data=data)
if result.status_code != 200:
response_data = result.json()
if not response_data["result"]:
return Response(
{
"result": False,
"message": "Failed to share template to sre store",
"code": err_code.OPERATION_FAIL.code,
}
)
response_data = result.json()
TemplateSharedRecord.create(
project_id=project_id,
template_id=template_id,
Expand Down

0 comments on commit 5877bb6

Please sign in to comment.