diff --git a/mailadmin/views.py b/mailadmin/views.py index 162c3f1..1d5dd80 100644 --- a/mailadmin/views.py +++ b/mailadmin/views.py @@ -3,6 +3,8 @@ from django.contrib.auth.decorators import login_required from django.contrib.auth.forms import AuthenticationForm from django.contrib.auth.models import User from django.shortcuts import render, redirect +import logging +from requests import exceptions from rest_framework import viewsets, views from rest_framework.permissions import IsAuthenticated from rest_framework.response import Response @@ -14,6 +16,9 @@ from mailadmin.serializers import UserSerializer, OrgUnitSerializer, AliasSerial from mailadmin.permissions import SourcePrefixOwner +logger = logging.getLogger(__name__) + + def index(request): if request.method == "POST": form = AuthenticationForm(data=request.POST) @@ -68,7 +73,12 @@ class AliasesView(views.APIView): if len(my_prefixes) == 0: return Response({'result': 'No results'}) # Need at least one - res = self._api.list_aliases_regex(regexp) + try: + res = self._api.list_aliases_regex(regexp) + except exceptions.RequestException as e: + logger.warning('mxapi errored {}'.format(e.strerror)) + return Response({'error': e.strerror}, status=status.HTTP_500_INTERNAL_SERVER_ERROR) + return Response(res) def post(self, request): diff --git a/mailadminsite/settings.py b/mailadminsite/settings.py index a0ff34a..893e1b2 100644 --- a/mailadminsite/settings.py +++ b/mailadminsite/settings.py @@ -88,7 +88,7 @@ STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') LOGIN_REDIRECT_URL = '/lists/' -DPD_API_URL= 'https://mxapi.neuf.no/api' +DPD_API_URL = 'http://localhost' DPD_API_USERNAME = "" DPD_API_PASSWORD = ""