Source code for codegrade.models.rate_limit_exceeded_exception
"""The module that defines the ``RateLimitExceededException`` model.
SPDX-License-Identifier: AGPL-3.0-only OR BSD-3-Clause-Clear
"""
from __future__ import annotations
import datetime
import typing as t
from dataclasses import dataclass, field
import cg_request_args as rqa
from httpx import Response
from ..utils import to_dict
from .base_error import BaseError
[docs]
@dataclass(kw_only=True)
class RateLimitExceededException(BaseError):
"""JSON representation of the exception, extending base APIException."""
#: A unique code identifying the kind of error that occurred.
code: t.Literal["RATE_LIMIT_EXCEEDED"]
#: The amount of time to wait before making another request.
retry_after: datetime.timedelta
raw_data: t.Optional[t.Dict[str, t.Any]] = field(init=False, repr=False)
data_parser: t.ClassVar[t.Any] = rqa.Lazy(
lambda: BaseError.data_parser.parser.combine(
rqa.FixedMapping(
rqa.RequiredArgument(
"code",
rqa.StringEnum("RATE_LIMIT_EXCEEDED"),
doc="A unique code identifying the kind of error that occurred.",
),
rqa.RequiredArgument(
"retry_after",
rqa.RichValue.TimeDelta,
doc="The amount of time to wait before making another request.",
),
)
)
)
def to_dict(self) -> t.Dict[str, t.Any]:
res: t.Dict[str, t.Any] = {
"code": to_dict(self.code),
"retry_after": to_dict(self.retry_after),
"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[RateLimitExceededException],
d: t.Dict[str, t.Any],
response: t.Optional[Response] = None,
) -> RateLimitExceededException:
parsed = cls.data_parser.try_parse(d)
res = cls(
code=parsed.code,
retry_after=parsed.retry_after,
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"):
pass