forked from shaba/openuds
Updated error page logic
This commit is contained in:
parent
ceb5fd9bde
commit
0a0f2771ae
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@ -19,7 +19,6 @@ gettext("UDS Client Download");
|
|||||||
gettext("Error launching service");
|
gettext("Error launching service");
|
||||||
gettext("Please wait until the service is launched.");
|
gettext("Please wait until the service is launched.");
|
||||||
gettext("Launching service");
|
gettext("Launching service");
|
||||||
gettext("Invalid error string");
|
|
||||||
gettext("Errors found");
|
gettext("Errors found");
|
||||||
gettext("Warning");
|
gettext("Warning");
|
||||||
gettext("Service is in maintenance and cannot be executed");
|
gettext("Service is in maintenance and cannot be executed");
|
||||||
|
@ -192,6 +192,12 @@ urlpatterns = [
|
|||||||
uds.web.views.customAuth,
|
uds.web.views.customAuth,
|
||||||
name='uds.web.views.customAuth',
|
name='uds.web.views.customAuth',
|
||||||
),
|
),
|
||||||
|
# Error message
|
||||||
|
re_path(
|
||||||
|
r'^uds/webapi/error/(?P<err>[0-9]+)$',
|
||||||
|
uds.web.views.errorMessage,
|
||||||
|
name='webapi.error',
|
||||||
|
),
|
||||||
# END WEB API
|
# END WEB API
|
||||||
# Costumization of GUI
|
# Costumization of GUI
|
||||||
re_path(
|
re_path(
|
||||||
|
@ -168,6 +168,7 @@ def udsJs(request: 'ExtendedHttpRequest') -> str:
|
|||||||
'user': reverse('page.index'),
|
'user': reverse('page.index'),
|
||||||
'customAuth': reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
|
'customAuth': reverse('uds.web.views.customAuth', kwargs={'idAuth': ''}),
|
||||||
'services': reverse('webapi.services'),
|
'services': reverse('webapi.services'),
|
||||||
|
'error': reverse('webapi.error', kwargs={'err': '9999'}),
|
||||||
'enabler': reverse(
|
'enabler': reverse(
|
||||||
'webapi.enabler',
|
'webapi.enabler',
|
||||||
kwargs={'idService': 'param1', 'idTransport': 'param2'},
|
kwargs={'idService': 'param1', 'idTransport': 'param2'},
|
||||||
|
@ -31,11 +31,13 @@
|
|||||||
"""
|
"""
|
||||||
import traceback
|
import traceback
|
||||||
import codecs
|
import codecs
|
||||||
|
import json
|
||||||
import logging
|
import logging
|
||||||
import typing
|
import typing
|
||||||
|
|
||||||
from django.utils.translation import ugettext_lazy as _
|
from django.utils.translation import ugettext_lazy as _
|
||||||
from django.shortcuts import render
|
from django.shortcuts import render
|
||||||
|
from django.http import HttpResponse
|
||||||
|
|
||||||
from django.http import HttpResponseRedirect
|
from django.http import HttpResponseRedirect
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
@ -46,7 +48,6 @@ from uds.models import ServicePool, Transport, UserService, Authenticator
|
|||||||
if typing.TYPE_CHECKING:
|
if typing.TYPE_CHECKING:
|
||||||
from django.http import (
|
from django.http import (
|
||||||
HttpRequest,
|
HttpRequest,
|
||||||
HttpResponse,
|
|
||||||
) # pylint: disable=ungrouped-imports
|
) # pylint: disable=ungrouped-imports
|
||||||
|
|
||||||
|
|
||||||
@ -101,24 +102,11 @@ strings = [
|
|||||||
|
|
||||||
def errorString(errorId: int) -> str:
|
def errorString(errorId: int) -> str:
|
||||||
errorId = int(errorId)
|
errorId = int(errorId)
|
||||||
if errorId < len(strings):
|
return str(strings[errorId]) if errorId < len(strings) else str(strings[0])
|
||||||
return strings[errorId]
|
|
||||||
return strings[0]
|
|
||||||
|
|
||||||
|
|
||||||
def errorView(request: 'HttpRequest', errorCode: int) -> HttpResponseRedirect:
|
def errorView(request: 'HttpRequest', errorCode: int) -> HttpResponseRedirect:
|
||||||
errorCode = int(errorCode)
|
return HttpResponseRedirect(reverse('page.error', kwargs={'err': errorCode}))
|
||||||
code = (errorCode >> 8) & 0xFF
|
|
||||||
errorCode = errorCode & 0xFF
|
|
||||||
|
|
||||||
errStr = errorString(errorCode)
|
|
||||||
if code != 0:
|
|
||||||
errStr += ' (code {0:04X})'.format(code)
|
|
||||||
|
|
||||||
errStr = codecs.encode(str(errStr).encode(), 'base64').decode().replace('\n', '')
|
|
||||||
|
|
||||||
logger.debug('Redirection to error view with %s', errStr)
|
|
||||||
return HttpResponseRedirect(reverse('page.error', kwargs={'err': errStr}))
|
|
||||||
|
|
||||||
|
|
||||||
def exceptionView(request: 'HttpRequest', exception: Exception) -> HttpResponseRedirect:
|
def exceptionView(request: 'HttpRequest', exception: Exception) -> HttpResponseRedirect:
|
||||||
@ -142,11 +130,11 @@ def exceptionView(request: 'HttpRequest', exception: Exception) -> HttpResponseR
|
|||||||
raise exception # Raise it so we can "catch" and redirect
|
raise exception # Raise it so we can "catch" and redirect
|
||||||
except UserService.DoesNotExist:
|
except UserService.DoesNotExist:
|
||||||
return errorView(request, ERR_USER_SERVICE_NOT_FOUND)
|
return errorView(request, ERR_USER_SERVICE_NOT_FOUND)
|
||||||
except ServicePool.DoesNotExist:
|
except ServicePool.DoesNotExist: # type: ignore
|
||||||
return errorView(request, SERVICE_NOT_FOUND)
|
return errorView(request, SERVICE_NOT_FOUND)
|
||||||
except Transport.DoesNotExist:
|
except Transport.DoesNotExist: # type: ignore
|
||||||
return errorView(request, TRANSPORT_NOT_FOUND)
|
return errorView(request, TRANSPORT_NOT_FOUND)
|
||||||
except Authenticator.DoesNotExist:
|
except Authenticator.DoesNotExist: # type: ignore
|
||||||
return errorView(request, AUTHENTICATOR_NOT_FOUND)
|
return errorView(request, AUTHENTICATOR_NOT_FOUND)
|
||||||
except InvalidUserException:
|
except InvalidUserException:
|
||||||
return errorView(request, ACCESS_DENIED)
|
return errorView(request, ACCESS_DENIED)
|
||||||
@ -160,7 +148,7 @@ def exceptionView(request: 'HttpRequest', exception: Exception) -> HttpResponseR
|
|||||||
return errorView(request, SERVICE_IN_MAINTENANCE)
|
return errorView(request, SERVICE_IN_MAINTENANCE)
|
||||||
except ServiceNotReadyError as e:
|
except ServiceNotReadyError as e:
|
||||||
# add code as high bits of idError
|
# add code as high bits of idError
|
||||||
return errorView(request, e.code << 8 | SERVICE_NOT_READY)
|
return errorView(request, SERVICE_NOT_READY)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.exception('Exception cautgh at view!!!')
|
logger.exception('Exception cautgh at view!!!')
|
||||||
return errorView(request, UNKNOWN_ERROR)
|
return errorView(request, UNKNOWN_ERROR)
|
||||||
@ -173,12 +161,12 @@ def error(request: 'HttpRequest', err: str) -> 'HttpResponse':
|
|||||||
"""
|
"""
|
||||||
return render(request, 'uds/modern/index.html', {})
|
return render(request, 'uds/modern/index.html', {})
|
||||||
|
|
||||||
# idError = int(idError)
|
|
||||||
# code = idError >> 8
|
|
||||||
# idError &= 0xFF
|
|
||||||
|
|
||||||
# errStr = errorString(idError)
|
def errorMessage(request: 'HttpRequest', err: int) -> 'HttpResponse':
|
||||||
# if code != 0:
|
"""
|
||||||
# errStr += ' (code {0:04X})'.format(code)
|
Error view, responsible of error display
|
||||||
|
"""
|
||||||
# return render(request, theme.template('error.html'), {'errorString': errStr})
|
return HttpResponse(
|
||||||
|
json.dumps({'error': errorString(err), 'code': str(err)}),
|
||||||
|
content_type='application/json',
|
||||||
|
)
|
||||||
|
@ -32,7 +32,7 @@
|
|||||||
import logging
|
import logging
|
||||||
|
|
||||||
# from .login import login, logout
|
# from .login import login, logout
|
||||||
from uds.web.util.errors import error
|
from uds.web.util.errors import error, errorMessage
|
||||||
from .service import (
|
from .service import (
|
||||||
transportOwnLink,
|
transportOwnLink,
|
||||||
transportIcon,
|
transportIcon,
|
||||||
|
Loading…
Reference in New Issue
Block a user