From 7ba069436255dc88372fd9b73db854477e7bf6f8 Mon Sep 17 00:00:00 2001 From: JENGE Date: Fri, 15 Sep 2023 14:57:25 +0200 Subject: [PATCH] fix: extras typing is not always dict[str,str] --- api/src/common/exceptions.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/api/src/common/exceptions.py b/api/src/common/exceptions.py index f4e58c61..58787e38 100644 --- a/api/src/common/exceptions.py +++ b/api/src/common/exceptions.py @@ -1,4 +1,5 @@ from enum import Enum +from typing import Any from fastapi import HTTPException from pydantic import BaseModel @@ -17,7 +18,7 @@ class ErrorResponse(BaseModel): type: str = "ApplicationException" message: str = "The requested operation failed" debug: str = "An unknown and unhandled exception occurred in the API" - extra: dict[str, str] | None = None + extra: dict[str, Any] | None = None class ApplicationException(Exception): @@ -26,13 +27,13 @@ class ApplicationException(Exception): type: str = "ApplicationException" message: str = "The requested operation failed" debug: str = "An unknown and unhandled exception occurred in the API" - extra: dict[str, str] | None = None + extra: dict[str, Any] | None = None def __init__( self, message: str = "The requested operation failed", debug: str = "An unknown and unhandled exception occurred in the API", - extra: dict[str, str] | None = None, + extra: dict[str, Any] | None = None, status: int = 500, severity: ExceptionSeverity = ExceptionSeverity.ERROR, ): @@ -43,7 +44,7 @@ def __init__( self.extra = extra self.severity = severity - def dict(self) -> dict[str, int | str | dict[str, str] | None]: + def dict(self) -> dict[str, int | str | dict[str, Any] | None]: return { "status": self.status, "type": self.type, @@ -58,7 +59,7 @@ def __init__( self, message: str = "You do not have the required permissions", debug: str = "Action denied because of insufficient permissions", - extra: dict[str, str] | None = None, + extra: dict[str, Any] | None = None, ): super().__init__(message, debug, extra, request_status.HTTP_403_FORBIDDEN, severity=ExceptionSeverity.WARNING) self.type = self.__class__.__name__ @@ -69,7 +70,7 @@ def __init__( self, message: str = "The requested resource could not be found", debug: str = "The requested resource could not be found", - extra: dict[str, str] | None = None, + extra: dict[str, Any] | None = None, ): super().__init__(message, debug, extra, request_status.HTTP_404_NOT_FOUND) self.type = self.__class__.__name__ @@ -80,7 +81,7 @@ def __init__( self, message: str = "Invalid data for the operation", debug: str = "Unable to complete the requested operation with the given input values.", - extra: dict[str, str] | None = None, + extra: dict[str, Any] | None = None, ): super().__init__(message, debug, extra, request_status.HTTP_400_BAD_REQUEST) self.type = self.__class__.__name__ @@ -91,7 +92,7 @@ def __init__( self, message: str = "The received data is invalid", debug: str = "Values are invalid for requested operation.", - extra: dict[str, str] | None = None, + extra: dict[str, Any] | None = None, ): super().__init__(message, debug, extra, request_status.HTTP_422_UNPROCESSABLE_ENTITY) self.type = self.__class__.__name__