mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-10-17 05:41:25 +02:00
Better errors display for sieve connections
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import axios from 'axios'
|
||||
import Cookies from 'js-cookie'
|
||||
import router from '@/router'
|
||||
import { useAuthStore } from '@/stores'
|
||||
import { useAuthStore, useBusStore } from '@/stores'
|
||||
|
||||
const _axios = axios.create()
|
||||
|
||||
@@ -36,6 +36,8 @@ _axios.interceptors.response.use(
|
||||
return Promise.reject(error)
|
||||
}
|
||||
if (error.response.status !== 401 || router.currentRoute.name === 'Login') {
|
||||
const busStore = useBusStore()
|
||||
busStore.displayNotification({ msg: error.response.data, type: 'error' })
|
||||
return Promise.reject(error)
|
||||
}
|
||||
const refreshToken = Cookies.get('refreshToken')
|
||||
|
||||
@@ -13,7 +13,6 @@ from drf_spectacular.utils import extend_schema, OpenApiParameter
|
||||
from rest_framework import response, viewsets
|
||||
from rest_framework.decorators import action
|
||||
|
||||
from modoboa.lib.connections import ConnectionError
|
||||
from modoboa.lib.viewsets import HasMailbox
|
||||
from modoboa.sievefilters import constants
|
||||
from modoboa.sievefilters.lib import SieveClient, SieveClientError
|
||||
@@ -35,10 +34,7 @@ class FilterSetViewSet(viewsets.ViewSet):
|
||||
serializer_class = serializers.FilterSetSerializer
|
||||
|
||||
def get_sieve_client(self, request):
|
||||
# try:
|
||||
return SieveClient(user=request.user.username, password=str(request.auth))
|
||||
# except ConnectionError as e:
|
||||
# raise
|
||||
|
||||
def list(self, request):
|
||||
"""Retrieve list of available filter sets."""
|
||||
|
||||
@@ -6,11 +6,10 @@ from typing import Optional, Tuple, Union
|
||||
from sievelib.factory import FiltersSet
|
||||
from sievelib import managesieve
|
||||
from sievelib.parser import Parser
|
||||
import six
|
||||
|
||||
from django.utils.translation import gettext as _
|
||||
|
||||
from modoboa.lib.connections import ConnectionsManager, ConnectionError
|
||||
from modoboa.lib.connections import ConnectionError
|
||||
from modoboa.lib.exceptions import ModoboaException
|
||||
from modoboa.parameters import tools as param_tools
|
||||
|
||||
@@ -18,10 +17,9 @@ from . import constants
|
||||
|
||||
|
||||
class SieveClientError(ModoboaException):
|
||||
http_code = 424
|
||||
http_code = 400
|
||||
|
||||
|
||||
# @six.add_metaclass(ConnectionsManager)
|
||||
class SieveClient:
|
||||
"""Sieve client."""
|
||||
|
||||
@@ -31,10 +29,10 @@ class SieveClient:
|
||||
if user and password:
|
||||
try:
|
||||
ret, msg = self.login(user, password)
|
||||
except managesieve.Error as e:
|
||||
raise ConnectionError(str(e))
|
||||
except (managesieve.Error, ConnectionError) as e:
|
||||
raise SieveClientError(str(e))
|
||||
if not ret:
|
||||
raise ConnectionError(msg)
|
||||
raise SieveClientError(msg)
|
||||
|
||||
def login(self, user: str, password: str) -> Tuple[bool, Union[str, None]]:
|
||||
conf = dict(param_tools.get_global_parameters("sievefilters"))
|
||||
|
||||
Reference in New Issue
Block a user