Skip to content

Commit

Permalink
fix: remove circular import
Browse files Browse the repository at this point in the history
  • Loading branch information
kikkomep committed Jan 18, 2024
1 parent 74007e1 commit 687e818
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions lifemonitor/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

Expand Down Expand Up @@ -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")
Expand All @@ -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__(
Expand Down
4 changes: 2 additions & 2 deletions lifemonitor/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

from lifemonitor import serializers

from .errors import handle_error

logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -259,6 +258,7 @@ def report_problem(status, title, detail=None, type=None, instance=None, extra_i
Returns a `Problem Details <https://tools.ietf.org/html/draft-ietf-appsawg-http-problem-00>`_ 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'
Expand Down

0 comments on commit 687e818

Please sign in to comment.