diff --git a/lifemonitor/errors.py b/lifemonitor/errors.py index b4dfbee4..7de4d74f 100644 --- a/lifemonitor/errors.py +++ b/lifemonitor/errors.py @@ -24,8 +24,6 @@ from flask import Blueprint, escape, render_template, request, url_for -from lifemonitor.utils import validate_url - # Config a module level logger logger = logging.getLogger(__name__) @@ -84,6 +82,7 @@ def handle_400(e: Exception = None, description: str = None): def handle_404(e: Exception = None): resource = request.args.get("resource", None, type=str) logger.debug(f"Resource not found: {resource}") + from lifemonitor.utils import validate_url if resource and not validate_url(resource): logger.error(f"Invalid URL: {resource}") return handle_400(description="Invalid URL") @@ -103,6 +102,7 @@ def handle_404(e: Exception = None): def handle_405(e: Exception = None): resource = request.args.get("resource", None, type=str) logger.debug(f"Method not allowed for resource {resource}") + from lifemonitor.utils import validate_url if not validate_url(resource): return handle_400(decription="Invalid URL") return __handle_error__( diff --git a/lifemonitor/exceptions.py b/lifemonitor/exceptions.py index ea4e6da4..e186b9ce 100644 --- a/lifemonitor/exceptions.py +++ b/lifemonitor/exceptions.py @@ -26,8 +26,6 @@ from lifemonitor import serializers -from .errors import handle_error - logger = logging.getLogger(__name__) @@ -229,6 +227,7 @@ def handle_exception(e: Exception): if logger.isEnabledFor(logging.DEBUG): logger.exception(e) if isinstance(e, LifeMonitorException): + from .errors import handle_error if request.accept_mimetypes.best == "text/html": return handle_error(e) return Response(response=e.to_json(), @@ -259,6 +258,7 @@ def report_problem(status, title, detail=None, type=None, instance=None, extra_i Returns a `Problem Details `_ error response. """ if request.accept_mimetypes.best == "text/html": + from .errors import handle_error return handle_error(LifeMonitorException(title=title, detail=detail, status=status)) if not type: type = 'about:blank'