Skip to content

Commit

Permalink
return error response on error
Browse files Browse the repository at this point in the history
  • Loading branch information
sunilshetye committed Jan 7, 2025
1 parent cdb1d41 commit 99bd66c
Showing 1 changed file with 15 additions and 11 deletions.
26 changes: 15 additions & 11 deletions blocks/simulationAPI/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,21 @@ def post(self, request, *args, **kwargs):
for chunk in file.chunks():
destination.write(chunk)

# Update the request data to include the file path
data = request.data.copy()
data['file_path'] = file_path
filename = CreateXcos(data['file_path'], '{}', 'abcd')
with open(filename, 'r') as file:
filecontent = file.read()

response = Response(filecontent, status=status.HTTP_200_OK,
content_type='application/octet-stream')
response['Content-Disposition'] = f'attachment; filename="{os.path.basename(filename)}"'
return response
try:
# Update the request data to include the file path
data = request.data.copy()
data['file_path'] = file_path
filename = CreateXcos(data['file_path'], '{}', 'abcd')
with open(filename, 'r') as file:
filecontent = file.read()

response = Response(filecontent, status=status.HTTP_200_OK,
content_type='application/octet-stream')
response['Content-Disposition'] = f'attachment; filename="{os.path.basename(filename)}"'
return response
except Exception as e:
logger.error('Error while creating Xcos file: %s', str(e))
return Response({"error": "Error while creating Xcos file"}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)


class CeleryResultView(APIView):
Expand Down

0 comments on commit 99bd66c

Please sign in to comment.