Repository navigation
Expand file tree
/
Copy pathratelimiterror.py
More file actions
58 lines (50 loc) · 1.98 KB
/
Copy pathratelimiterror.py
File metadata and controls
58 lines (50 loc) · 1.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT."""
from __future__ import annotations
from dataclasses import dataclass, field
import httpx
from moderation_api.errors import ModerationAPIError
from moderation_api.models import (
errorissue as models_errorissue,
ratelimiterror as models_ratelimiterror,
)
from moderation_api.types import BaseModel
from moderation_api.utils import validate_const
import pydantic
from pydantic.functional_validators import AfterValidator
from typing import List, Literal, Optional
from typing_extensions import Annotated
class RateLimitErrorData(BaseModel):
code: models_ratelimiterror.RateLimitErrorCode
r"""Exactly what went wrong. Stable; safe to branch on. New codes may be added.
- `rate_limit_exceeded`: Too many requests. Wait for the `Retry-After` seconds.
"""
message: str
r"""Human-readable explanation."""
request_id: str
r"""Identifies this request. Include it when you contact support."""
doc_url: str
r"""Documentation for this `code`."""
type: Annotated[
Annotated[
Literal["rate_limit_error"],
AfterValidator(validate_const("rate_limit_error")),
],
pydantic.Field(alias="type"),
] = "rate_limit_error"
r"""Broad error category. Stable; safe to switch on."""
issues: Optional[List[models_errorissue.ErrorIssue]] = None
r"""Validation problems, when the request body is invalid."""
@dataclass(unsafe_hash=True)
class RateLimitError(ModerationAPIError):
r"""Too many requests. Retry after the number of seconds in the `Retry-After` header."""
data: RateLimitErrorData = field(hash=False)
def __init__(
self,
data: RateLimitErrorData,
raw_response: httpx.Response,
body: Optional[str] = None,
):
fallback = body or raw_response.text
message = str(data.message) or fallback
super().__init__(message, raw_response, body)
object.__setattr__(self, "data", data)