Skip to content

http_auth_exception

mlte/backend/api/auth/http_auth_exception.py

Exception used for authentication issues.

HTTPAuthException

Bases: HTTPException

Exception used for HTTP authentication issues.

Source code in mlte/backend/api/auth/http_auth_exception.py
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
class HTTPAuthException(HTTPException):
    """Exception used for HTTP authentication issues."""

    def __init__(
        self,
        status_code: int = codes.UNAUTHORIZED,
        error: str = "",
        error_decription: str = "",
    ):
        """Constructor, calls based class with predefined params."""
        header_value = "Bearer"
        if error != "":
            header_value += f' error="{error}"'
            header_value += f', error_description="{error_decription}"'
        headers = {"WWW-Authenticate": header_value}

        super().__init__(
            status_code=status_code,
            headers=headers,
        )

__init__(status_code=codes.UNAUTHORIZED, error='', error_decription='')

Constructor, calls based class with predefined params.

Source code in mlte/backend/api/auth/http_auth_exception.py
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
def __init__(
    self,
    status_code: int = codes.UNAUTHORIZED,
    error: str = "",
    error_decription: str = "",
):
    """Constructor, calls based class with predefined params."""
    header_value = "Bearer"
    if error != "":
        header_value += f' error="{error}"'
        header_value += f', error_description="{error_decription}"'
    headers = {"WWW-Authenticate": header_value}

    super().__init__(
        status_code=status_code,
        headers=headers,
    )

HTTPTokenException

Bases: HTTPException

Exception used for issues when a token is requested.

Source code in mlte/backend/api/auth/http_auth_exception.py
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
class HTTPTokenException(HTTPException):
    """Exception used for issues when a token is requested."""

    def __init__(
        self,
        status_code: int = codes.BAD_REQUEST,
        error: str = "",
        error_decription: str = "",
    ):
        """Constructor, calls based class with predefined params."""
        headers = {"Content-Type": "application/json;charset=UTF-8"}
        details = {}
        if error != "":
            details = {"error": error, "error_description": error_decription}

        super().__init__(
            status_code=status_code,
            headers=headers,
            detail=details,
        )

__init__(status_code=codes.BAD_REQUEST, error='', error_decription='')

Constructor, calls based class with predefined params.

Source code in mlte/backend/api/auth/http_auth_exception.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
def __init__(
    self,
    status_code: int = codes.BAD_REQUEST,
    error: str = "",
    error_decription: str = "",
):
    """Constructor, calls based class with predefined params."""
    headers = {"Content-Type": "application/json;charset=UTF-8"}
    details = {}
    if error != "":
        details = {"error": error, "error_description": error_decription}

    super().__init__(
        status_code=status_code,
        headers=headers,
        detail=details,
    )

json_content_exception_handler(request, exc)

Exception handler that doesn't add the "details" key to a JSON response.

Source code in mlte/backend/api/auth/http_auth_exception.py
16
17
18
19
20
21
22
def json_content_exception_handler(
    request: Request, exc: StarletteHTTPException
) -> JSONResponse:
    """Exception handler that doesn't add the "details" key to a JSON response."""
    return JSONResponse(
        status_code=exc.status_code, headers=exc.headers, content=exc.detail
    )