handle errors

This commit is contained in:
Diego Calvo
2021-02-10 10:58:09 +01:00
parent c4c03653e2
commit 3b801768e4

View File

@@ -9,6 +9,7 @@ from django.conf import settings
from django.db.models import Q from django.db.models import Q
# Create your views here. # Create your views here.
from rest_framework import status
from rest_framework import viewsets from rest_framework import viewsets
from rest_framework.response import Response from rest_framework.response import Response
from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAdminUser, IsAuthenticated from rest_framework.permissions import IsAuthenticatedOrReadOnly, IsAdminUser, IsAuthenticated
@@ -127,7 +128,7 @@ def load_coop_products(request):
logging.error(f"Could not parse {row}") logging.error(f"Could not parse {row}")
return Response() return Response()
except Exception as e: except Exception as e:
return Response({"errors": {"details": str(type(e))}}) return Response({"errors": {"details": str(type(e))}}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)
@api_view(['GET',]) # include allowed methods @api_view(['GET',]) # include allowed methods
@@ -168,4 +169,4 @@ def product_search(request):
product_serializer = ProductSerializer(result_set, many=True) product_serializer = ProductSerializer(result_set, many=True)
return Response(data={"filters": filters, "products": product_serializer.data}) return Response(data={"filters": filters, "products": product_serializer.data})
except Exception as e: except Exception as e:
return Response({"errors": {"details": str(type(e))}}) return Response({"errors": {"details": str(type(e))}}, status=status.HTTP_500_INTERNAL_SERVER_ERROR)