Source code for maptekblastlogic.models.error_model

from __future__ import annotations

from collections.abc import Mapping
from typing import Any, TypeVar, cast

from attrs import define as _attrs_define

from ..types import UNSET, Unset

T = TypeVar("T", bound="ErrorModel")


[docs] @_attrs_define class ErrorModel: """A structure of error messages given when a request could not be fulfilled.""" title: None | str | Unset = UNSET details: None | str | Unset = UNSET errors: list[str] | None | Unset = UNSET
[docs] def to_dict(self) -> dict[str, Any]: title: None | str | Unset if isinstance(self.title, Unset): title = UNSET else: title = self.title details: None | str | Unset if isinstance(self.details, Unset): details = UNSET else: details = self.details errors: list[str] | None | Unset if isinstance(self.errors, Unset): errors = UNSET elif isinstance(self.errors, list): errors = self.errors else: errors = self.errors field_dict: dict[str, Any] = {} field_dict.update({}) if title is not UNSET: field_dict["title"] = title if details is not UNSET: field_dict["details"] = details if errors is not UNSET: field_dict["errors"] = errors return field_dict
[docs] @classmethod def from_dict(cls: type[T], src_dict: Mapping[str, Any]) -> T: d = dict(src_dict) def _parse_title(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(None | str | Unset, data) title = _parse_title(d.pop("title", UNSET)) def _parse_details(data: object) -> None | str | Unset: if data is None: return data if isinstance(data, Unset): return data return cast(None | str | Unset, data) details = _parse_details(d.pop("details", UNSET)) def _parse_errors(data: object) -> list[str] | None | Unset: if data is None: return data if isinstance(data, Unset): return data try: if not isinstance(data, list): raise TypeError() errors_type_0 = cast(list[str], data) return errors_type_0 except (TypeError, ValueError, AttributeError, KeyError): pass return cast(list[str] | None | Unset, data) errors = _parse_errors(d.pop("errors", UNSET)) error_model = cls( title=title, details=details, errors=errors, ) return error_model