Skip to content

Commit

Permalink
fix: extras typing is not always dict[str,str]
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenengelsen committed Sep 18, 2023
1 parent 961a7b2 commit 7ba0694
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions api/src/common/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from enum import Enum
from typing import Any

from fastapi import HTTPException
from pydantic import BaseModel
Expand All @@ -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):
Expand All @@ -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,
):
Expand All @@ -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,
Expand All @@ -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__
Expand All @@ -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__
Expand All @@ -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__
Expand All @@ -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__
Expand Down

0 comments on commit 7ba0694

Please sign in to comment.