Source code for codegrade.models.failed_to_send_email_exception

"""The module that defines the ``FailedToSendEmailException`` model.

SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""

from __future__ import annotations

import typing as t
from dataclasses import dataclass, field

import cg_request_args as rqa
from httpx import Response

from .. import parsers
from ..utils import to_dict
from .upstream_service_exception import UpstreamServiceException
from .user import User, UserParser


[docs] @dataclass(kw_only=True) class FailedToSendEmailException(UpstreamServiceException): """The JSON representation of `FailedToSendEmailException`.""" #: A unique code identifying the kind of error that occurred. code: t.Literal["MAILING_FAILED"] #: Every user the email was addressed to. all_users: t.Sequence[User] #: The users among `all_users` the email could not be delivered to. failed_users: t.Sequence[User] raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False) data_parser: t.ClassVar[t.Any] = rqa.Lazy( lambda: UpstreamServiceException.data_parser.parser.combine( rqa.FixedMapping( rqa.RequiredArgument( "code", rqa.StringEnum("MAILING_FAILED"), doc="A unique code identifying the kind of error that occurred.", ), rqa.RequiredArgument( "all_users", rqa.List(UserParser), doc="Every user the email was addressed to.", ), rqa.RequiredArgument( "failed_users", rqa.List(UserParser), doc="The users among `all_users` the email could not be delivered to.", ), ) ) ) def to_dict(self) -> t.Dict[str, t.Any]: res: t.Dict[str, t.Any] = { "code": to_dict(self.code), "all_users": to_dict(self.all_users), "failed_users": to_dict(self.failed_users), "message": to_dict(self.message), "description": to_dict(self.description), "request_id": to_dict(self.request_id), } return res @classmethod def from_dict( cls: t.Type[FailedToSendEmailException], d: t.Dict[str, t.Any], response: t.Optional[Response] = None, ) -> FailedToSendEmailException: parsed = cls.data_parser.try_parse(d) res = cls( code=parsed.code, all_users=parsed.all_users, failed_users=parsed.failed_users, message=parsed.message, description=parsed.description, request_id=parsed.request_id, response=response, ) res.raw_data = d return res
import os if os.getenv("CG_GENERATING_DOCS", "False").lower() in ("", "true"): from .base_error import BaseError