Repository navigation
Expand file tree
/
Copy pathauthenticationerror.py
More file actions
61 lines (53 loc) · 2.18 KB
/
Copy pathauthenticationerror.py
File metadata and controls
61 lines (53 loc) · 2.18 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
59
60
61
"""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 (
authenticationerror as models_authenticationerror,
errorissue as models_errorissue,
)
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 AuthenticationErrorData(BaseModel):
code: models_authenticationerror.AuthenticationErrorCode
r"""Exactly what went wrong. Stable; safe to branch on. New codes may be added.
- `unauthorized`: Authentication failed.
- `missing_api_key`: No API key in the `Authorization` header.
- `malformed_api_key`: The `Authorization` header does not contain a valid key format.
- `invalid_api_key`: The API key does not exist or was revoked.
"""
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["authentication_error"],
AfterValidator(validate_const("authentication_error")),
],
pydantic.Field(alias="type"),
] = "authentication_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 AuthenticationError(ModerationAPIError):
r"""The API key is missing, invalid or revoked."""
data: AuthenticationErrorData = field(hash=False)
def __init__(
self,
data: AuthenticationErrorData,
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)