Skip to content

Commit

Permalink
HOSTFIX: HTTP error.
Browse files Browse the repository at this point in the history
  • Loading branch information
Angel-Dijoux committed Nov 11, 2023
1 parent 95e498f commit 562856b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/blueprints/route_handler.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
from http.client import HTTPException
from typing import Callable
from flask import Blueprint, jsonify
from flasgger import swag_from
from enum import Enum
import jwt
from loguru import logger

from src.constants.http_status_codes import HTTP_200_OK, HTTP_500_INTERNAL_SERVER_ERROR
from src.constants.http_status_codes import (
HTTP_200_OK,
HTTP_401_UNAUTHORIZED,
HTTP_500_INTERNAL_SERVER_ERROR,
)


class HttpMethod(Enum):
Expand All @@ -24,7 +30,16 @@ def decorator(func: Callable) -> Callable:
def inner_wrapper(*args, **kwargs):
try:
return jsonify(func(*args, **kwargs)), HTTP_200_OK
except jwt.ExpiredSignatureError as e:
# Handle JWT token expiration: return 401 Unauthorized
logger.warning(f"Expired JWT token in {func.__name__}: {str(e)}")
return "", HTTP_401_UNAUTHORIZED
except HTTPException as e:
# Handle other HTTP exceptions
logger.warning(f"HTTPException in {func.__name__}: {str(e)}")
return "", e.code
except Exception as e:
# Handle generic exceptions
logger.warning(f"Error in {func.__name__}: {str(e)}")
return "", HTTP_500_INTERNAL_SERVER_ERROR

Expand Down

0 comments on commit 562856b

Please sign in to comment.