Skip to content

Commit 3528682

Browse files
n-thumanngreenbonebot
authored andcommitted
Add: data field to ModelError
1 parent 2079946 commit 3528682

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

pontos/models/__init__.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
from dataclasses import dataclass
88
from datetime import date, datetime, timezone
99
from inspect import isclass
10-
from typing import Any, Dict, Type, Union, get_args, get_origin, get_type_hints
10+
from typing import (
11+
Any,
12+
Dict,
13+
Type,
14+
Union,
15+
get_args,
16+
get_origin,
17+
get_type_hints,
18+
)
1119

1220
from dateutil import parser as dateparser
1321

1422
from pontos.enum import StrEnum
1523
from pontos.errors import PontosError
24+
from pontos.nvd.api import JSON
1625

1726
__all__ = (
1827
"Model",
@@ -29,6 +38,10 @@ class ModelError(PontosError):
2938
Errors raised for Models
3039
"""
3140

41+
def __init__(self, message: str, data: JSON):
42+
super().__init__(message)
43+
self.data = data
44+
3245

3346
def dotted_attributes(obj: Any, data: Dict[str, Any]) -> Any:
3447
"""
@@ -162,7 +175,8 @@ def from_dict(cls, data: Dict[str, Any]):
162175
else:
163176
raise ModelError(
164177
f"Error while creating {cls.__name__} model. Could not set " # pylint: disable=line-too-long # noqa: E501
165-
f"value for property '{name}' from '{value}'."
178+
f"value for property '{name}' from '{value}'.",
179+
data,
166180
) from e
167181

168182
if name in type_hints:

0 commit comments

Comments
 (0)