Skip to content

Commit 0d94120

Browse files
committed
chore: add run-time type-check to proto_dto | use custom exceptions
1 parent 37d7dbc commit 0d94120

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

archipy/models/dtos/base_protobuf_dto.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from typing import Any, ClassVar, Self
22

33
from archipy.models.dtos.base_dtos import BaseDTO
4+
from archipy.models.errors import InvalidEntityTypeError
45

56
try:
67
from google.protobuf.json_format import MessageToDict, ParseDict
@@ -33,9 +34,10 @@ def from_proto(cls, request: Message) -> Self:
3334
raise NotImplementedError(f"{cls.__name__} is not mapped to a proto class.")
3435

3536
if not isinstance(request, cls._proto_class):
36-
raise TypeError(
37-
f"{cls.__name__}.from_proto expected {cls._proto_class.__name__}, "
38-
f"but got {type(request).__name__} instead."
37+
raise InvalidEntityTypeError(
38+
message=f"{cls.__name__}.from_proto expected a different type of request.",
39+
expected_type=cls._proto_class.__name__,
40+
actual_type=type(request).__name__,
3941
)
4042

4143
input_data = MessageToDict(

0 commit comments

Comments
 (0)